IDE_ID NUM1001 2
1001 5
1001 7
2001 2
2001 3
2001 5
表中有2个字段,我想要的结果是
select sum(num) from tab where IDE_ID=1001
select sum(num) from tab where IDE_ID=2001也就是分别统计这两个ID的数量总和,能不能以一句SQL语句写出来呢?
1001 5
1001 7
2001 2
2001 3
2001 5
表中有2个字段,我想要的结果是
select sum(num) from tab where IDE_ID=1001
select sum(num) from tab where IDE_ID=2001也就是分别统计这两个ID的数量总和,能不能以一句SQL语句写出来呢?
sum( NUM )from tab
where IDE_ID in (1001 ,2001 )group by IDE_ID
select sum(num) from tab where IDE_ID=1001
union all
select sum(num) from tab where IDE_ID=2001
这种方式是竖着显示的
方法2
select (select sum(num) from tab where IDE_ID=1001) a,
(select sum(num) from tab where IDE_ID=2001) b from dual
这种方式是横着显示的
看你想用哪种了