标题:数据求和显示,求大神指导。
只看楼主
zcdjt
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:99
专家分:181
注 册:2014-9-9
结帖率:85.71%
 问题点数:0 回复次数:1 
数据求和显示,求大神指导。
select DepartmentName,SectionOffice,
(select count(*) ShareCount from tblTaskFlowRecord where OperationType in (2,3)  and CreateWechatOpenId=c.OpenId group by CreateWechatOpenId) ShareCount--分享量
from (select distinct CreateWechatOpenId from tblTaskFlowRecord) a
join SysUser c on a.CreateWechatOpenId=c.OpenId
left join tblDepartmentRelation d on c.Mobile=d.Phone

怎么把为空的数据统计成一条显示?
搜索更多相关主题的帖子: 数据 求和 显示 select from 
2018-11-10 15:16
zcdjt
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:99
专家分:181
注 册:2014-9-9
得分:0 
;with m as (
-- 下面是你原来的
select DepartmentName,
       SectionOffice,
       (select count(*) ShareCount
          from tblTaskFlowRecord
         where OperationType in (2, 3)
           and CreateWechatOpenId = c.OpenId
         group by CreateWechatOpenId) ShareCount --分享量
  from (select distinct CreateWechatOpenId from tblTaskFlowRecord) a
  join SysUser c
    on a.CreateWechatOpenId = c.OpenId
  left join tblDepartmentRelation d
    on c.Mobile = d.Phone
-- 上面是你原来的
)
,cte AS (
   select
       ROW_NUMBER() OVER (ORDER BY DepartmentName) AS rid,
        DepartmentName,
       SectionOffice,
       sum(ShareCount) ShareCount
  from m
  group by
       DepartmentName,
       SectionOffice
)
SELECT * FROM cte where rowNumber BETWEEN 1 AND 20

今朝醉
2018-11-12 11:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-491136-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.066452 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved