Blobonator Blobonator - 6 months ago 10
SQL Question

SQL: Split Dataset into two columns

I have a table like this:
http://i.stack.imgur.com/tNfFD.png

Now I want a table like this with a SELECT command:
http://i.stack.imgur.com/c2rpt.png

time1 and value1 is from the data with c_id=4,
time2 and value2 is from the data with c_id=5

Is it possible to create a SELECT command to do that?

I hope you can help

Answer

Yiu can use an inner join

select a.time as time1, a.value as value1, b.time as time2, b.value as value2
from my_table as a 
inner join my_table as b on a.time = b.time
and a.c_id= 4
and b.c_id= 5;
Comments