表结构
table a:
id,a,b,c,d
e,1,2,3,4
e,2,2,2,2
f,3,3,3,3
f,2,1,3,4要求统计SQL,显示结构要如下。
e,sum(a)
e,sum(b)
e,sum(c)
e,sum(d)
f,sum(a)
f,sum(b)
f,sum(c)
f,sum(d)请高手指点。
table a:
id,a,b,c,d
e,1,2,3,4
e,2,2,2,2
f,3,3,3,3
f,2,1,3,4要求统计SQL,显示结构要如下。
e,sum(a)
e,sum(b)
e,sum(c)
e,sum(d)
f,sum(a)
f,sum(b)
f,sum(c)
f,sum(d)请高手指点。
(select id,sum(a) v,'a'c from 表 group by id union all
select id,sum(b) v,'b' c from 表 group by id union all
select id,sum(c) v,'c' c from 表 group by id union all
select id,sum(d) v,'d' c from 表 group by id) a
order by id,c
group by id