Sql Server 2000使用问题
内容如下:表:mytable  包含字段:aa,bb,cc,dd,ee,ff
查询要求:在  select aa,bb,cc sum(dd) as d,sum(ee) as e,sum(ff) as f from mytable group bb,cc order by aa 结果集中过虑掉 列 d,e,f为0 或者为空的记录

解决方案 »

  1.   

    group指定的字段才能用sum这样的聚集函数,所有你的要求应该不能实现,
    如果要求是
    select aa,bb,cc, sub(dd), sum(ee), sum(ff) from mytable group by dd,ee,ff having dd<>0 and ee<>0 and ff<>0
    用having给出聚集的附加条件
      

  2.   

    select aa,bb,cc, sum(isnull(dd,0)), sum(isnull(ee,0)), sum(isnull(ff,0)) from mytable group by aa,bb,cc having sum(isnull(dd,0))<>0 and sum(isnull(ee,0))<>0 and sum(isnull(ff,0))<>0
    order by aa
      

  3.   

    对于bb,cc这些字段有很多是相同的,我是想查出相同的bb,cc 的sum(dd)……
      

  4.   

    aa字段不为数字,可以采用
    select max(aa) aa,bb,cc, sum(isnull(dd,0)), sum(isnull(ee,0)), sum(isnull(ff,0)) from mytable group by bb,cc having sum(isnull(dd,0))<>0 and sum(isnull(ee,0))<>0 and sum(isnull(ff,0))<>0
    order by aa