oracle 统计分组数量
表A
operator1 operator2 operator3 num
111 222 333 10
222 111 444 20
222 333 444 30
现在想要统计出每个operator的num的和,即
111:(10 + 20) = 30;
222:(10 + 20 + 30) = 60;
333:(10 + 30) = 40;
444:(20 + 30) = 50;
查询出来的结果为
operator count
111 30
222 60
333 40
444 50
在线等, 谢谢了...
------解决方案--------------------
SQL code
select operator,sum(num) sum from (
select operator1 operator,num from A
union all
select operator2,num from A
union all
select operator3,num from A) t
group by t.operator
order by t.operator;