我有一个类似
的表格mss | circle | psr | date
-----+--------+-------+----------
m1 | mum | 99.6 | 20190211
m2 | mum | 98.6 | 20190211
m3 | mum | 97.6 | 20190211
m1 | mum | 9.6 | 20190212
m2 | mum | 93.6 | 20190212
m3 | mum | 46 | 20190212
m1 | mum | 9.36 | 20190213
m2 | mum | 99.36 | 20190213
m3 | mum | 29.36 | 20190213
答案 0 :(得分:2)
使用条件聚合
select mss,circle, max(case when date='20190211' then psr end) date11th,
max(case when date='20190212' then psr end) date12th,
max(case when date='20190213' then psr end) date13th
from table group by mss,circle
答案 1 :(得分:0)
下面是查询-
select t.mss, t.circle,
max(case when t.date=20190211 then t.psr else 0 end) as date11th,
max(case when t.date=20190212 then t.psr else 0 end) as date12th,
max(case when t.date=20190213 then t.psr else 0 end) as date13th
from table t group by t.mss, t.circle;