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语句写出来呢?

解决方案 »

  1.   

    select IDE_ID,sum(num) from tab where group by IDE_ID
      

  2.   

    select ide_id,sum(num) from tab group by ide_id
      

  3.   

    select IDE_ID
        sum( NUM )from tab
    where IDE_ID  in (1001 ,2001 )group by IDE_ID
      

  4.   

    方法1
    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
    这种方式是横着显示的
    看你想用哪种了