Reputation: 307
this may be a dumb question but how can I rename the mysql output? Like for example on the column if i select the value column like
SELECT val As New_Value
then on the output the name of that column would be New_Value right? But what if I want to rename the row? Like on the New_Value:
New_Value |
Apple |
Here's my code:
select t1.location AS Location,
max(case when t2.locationid = '2847' then t2.value end) MR,
max(case when t2.locationid = '2839' then t2.value end) Flow,
max(case when t2.locationid = '2834' then t2.value end) Pressure,
max(case when t2.locationid = '2836' then t2.value end) Level
from table2 t2
inner join table1 t1
on t1.id = '2847'
group by t1.location
the output of this is
Location | MR | Flow | Pressure | Level
location/east/flow | 20 | 25 | 34 | 45
this is the output i want, i just want it to be clean and I want to be able to add new text:
Location | MR | Flow | Pressure | Level
2012 East | 20 | 25 | 34 | 45
Upvotes: 0
Views: 583
Reputation: 522
I'm not sure exactly what you mean because rows have no real order unless you use a order by statement.
What I think you mean is you want to change the value of each row.
In this case, you can use CASE WHEN.
Upvotes: 0
Reputation: 3896
You could do:
SELECT CONCAT('New_', val) As New_Value
Be careful how you use this though, as you're going to retrieve different data than is actually in your database.
Upvotes: 1