我有一张类似这个的桌子
Date | Cond | Time
--------|--------|------
18/03/19| 1 | 13:07
18/03/19| 0 | 16:07
我希望有一个选择,可以生成类似于使用join或union或任何条件的东西
Date |Time1| Time2
--------|-----|------
18/03/19|13:07| 16:07
最好的祝福
您可以使用条件聚合:
select date, max(case when cond = 1 then time end) as time_1,
max(case when cond = 0 then time end) as time_0
from t
group by date
order by date;
使用聚合函数
select date,min(time),max(time)
from table group by date