我有一表数据如下
ID AID SZ
------------
a1 c1 10
a1 c2 13
a1 c3 8
a2 c1 6
a2 c2 5
a2 c3 57
报表为
ID c1 c2 c3 max(c1,c2,c3)
-------------------------------
a1 10 13 8 13
a2 6 5 57 57
请高手指点该如何设计报表
ID AID SZ
------------
a1 c1 10
a1 c2 13
a1 c3 8
a2 c1 6
a2 c2 5
a2 c3 57
报表为
ID c1 c2 c3 max(c1,c2,c3)
-------------------------------
a1 10 13 8 13
a2 6 5 57 57
请高手指点该如何设计报表
sum(Case aid when 'c2' then sz end),
sum(Case aid when 'c3' then sz end),
max(sz) from t1 group by id
sum(Case aid when 'c2' then sz end) as c2,
sum(Case aid when 'c3' then sz end) as c3,
max(sz) from t1 group by id