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 或者为空的记录
内容如下:表: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 或者为空的记录
如果要求是
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给出聚集的附加条件
order by 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