列1 列2 列3  列4 列5 列6 列7 
  001 002 003  21  a1  a3  10001 
  002 002 003  01  F2  F3  10001 
  003 002 003  23  D2  D3  10001 
  003 002 003  22  D2  D3  10001 
  003 002 003  02  D2  D3  10001 
  003 002 003  03  D2  D3  10001 
  003 002 003  23  D2  D3  10001 
  ............
求 列4=(21 22 23)的和 没有其他条件

解决方案 »

  1.   

    还有一个 求 列4<>(21 ,22 ,23)的列1的和 没有其他条件 
      

  2.   

    列4=(21 22 23)的列1的和 没有其他条件
    select 列1 from A where 列4 in(21, 22, 23)
    还有一个 求 列4 <>(21 ,22 ,23)的列1的和 没有其他条件
    select 列1 from A where 列4 not in(21, 22, 23)
      

  3.   

    select sum(列1) from where 列4 in ('21','22','23')
    select sum(列1) from where 列4 not in ('21','22','23')
      

  4.   

    先谢谢 楼上
     不过你写错了
    SELECT
        SUM(列1) AS 列1    
    FROM
        (SELECT
            DECODE(列4,'21','A','22','A','23','A','D') AS 列4,
            列1
        FROM
            A
        )
    WHERE
        列4 ='A'
    这是我想的一个方法
    但我觉得不好
    不知道还有没有更好的
      

  5.   

    select sum(列1) from tablename where 列4 in ('21','22','23') 
    select sum(列1) from  tablename where 列4 not in ('21','22','23')