消息130,级别15,状态 1,第 9 行 不能对包含聚合或子查询的表达式执行聚合函数。

select b.projectcd,b.projectnm,h.devicetypenm,sum(j.sums) as todaysums,sum((
select sum(j.sums)

       from  cloud_cm..cm_user a,cloud_ri..bi_project b,cloud_ri..bi_project_dt c,
       cloud_ri..bi_disaster d,cloud_ri..bi_dt_st_device e,cloud_ri..bi_stbprp_b f,
       cloud_ri..bi_device g,cloud_ri..bi_devicetype h,cloud_ri..ri_receivesum j
      where a.projectcd=b.projectcd and b.projectcd=c.projectcd  and c.dtcd=d.dtcd
      and e.dtcd=d.dtcd  and e.stcd=f.stcd  and e.devicecd=g.devicecd
      and h.devicetypecd=g.devicetypecd  and g.devicecd=j.devicecd  and a.usercd=2
       )) as    allsums

       from  cloud_cm..cm_user a,cloud_ri..bi_project b,cloud_ri..bi_project_dt c,
       cloud_ri..bi_disaster d,cloud_ri..bi_dt_st_device e,cloud_ri..bi_stbprp_b f,
       cloud_ri..bi_device g,cloud_ri..bi_devicetype h,cloud_ri..ri_receivesum j
      where a.projectcd=b.projectcd and b.projectcd=c.projectcd  and c.dtcd=d.dtcd
      and e.dtcd=d.dtcd  and e.stcd=f.stcd  and e.devicecd=g.devicecd
      and h.devicetypecd=g.devicetypecd  and g.devicecd=j.devicecd  
       and DATEDIFF(day,j.tm,GETDATE())=20            and a.usercd=2
      group by b.projectcd,b.projectnm,h.devicetypenm

2个回答

分组的原因导致 计算失败

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问