sql名称显示,求指教?

z1_23456 2018-12-04 05:38:48


select --Mobile,a.UseWechatOpenId,UserName,
GroupName,isnull(a.ShareScore,0)+isnull(c.SecondShareScore,0) Integral,
isnull(a.ShareCount,0)ShareCount,isnull(a.ClickCount,0)ClickCount,isnull(a.JoinInUserCount,0)JoinInUserCount,isnull(b.ClickUserCount,0)ClickUserCount
from(
select a.TaskId,GroupName,
sum(case when OperationType=1 then 0 else 1 end) ShareCount,
sum(case when OperationType=1 then 1 else 0 end) ClickCount,SUM(ShareScore) ShareScore,
count( distinct ForwardWechatOpenId) JoinInUserCount
from tblTaskFlowRecord a left join tblTask b on a.TaskId=b.TaskId left join (

select a.TaskId,a.usergroupid,c.openid,e.GroupName from tblTaskRelationUserGroup a
left join tblUserGroupRelation b on a.UserGroupRelationId=b.UserGroupRelationId and b.IsDel=0
left join SysUser c on b.userid=c.userid
right join tblUserGroup e on e.UserGroupId = b.UserGroupId and e.IsDel = 0
)c on a.TaskId=c.TaskId and a.UseWechatOpenId=c.OpenId --where a.TaskId='CA83758E-9F6F-4376-88B1-E3B1703E011D'
group by a.TaskId,GroupName
) a left join (
select a.TaskId,count( distinct ForwardWechatOpenId) ClickUserCount
from tblTaskFlowRecord a where a.OperationType=1
group by a.TaskId

) b on a.TaskId=b.TaskId left join(

select TaskId,SUM(SecondShareScore) SecondShareScore
from tblTaskFlowRecord where OperationType=1
group by TaskId

) c on b.TaskId=c.TaskId
order by ShareCount desc

我想让名称显示出来,请问怎么显示?求大神指教。
...全文
157 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
z1_23456 2018-12-05
  • 打赏
  • 举报
回复
谢谢,我再看看。
RINK_1 2018-12-04
  • 打赏
  • 举报
回复
试试以下的,


select --Mobile,a.UseWechatOpenId,UserName,
GroupName,isnull(a.ShareScore,0)+isnull(c.SecondShareScore,0) Integral,
 isnull(a.ShareCount,0)ShareCount,isnull(a.ClickCount,0)ClickCount,isnull(a.JoinInUserCount,0)JoinInUserCount,isnull(b.ClickUserCount,0)ClickUserCount 
 from(
select  a.TaskId,GroupName,
sum(case when OperationType=1 then 0 else 1 end) ShareCount,
sum(case when OperationType=1 then 1 else 0 end) ClickCount,SUM(ShareScore) ShareScore,
count( distinct ForwardWechatOpenId) JoinInUserCount  
from tblTaskFlowRecord a left join tblTask b on a.TaskId=b.TaskId right join (

select a.TaskId,a.usergroupid,c.openid,e.GroupName from tblTaskRelationUserGroup a
left join tblUserGroupRelation b on a.UserGroupRelationId=b.UserGroupRelationId and b.IsDel=0 
left join SysUser c on b.userid=c.userid 
right join tblUserGroup e on e.UserGroupId = b.UserGroupId and e.IsDel = 0
)c on a.TaskId=c.TaskId and a.UseWechatOpenId=c.OpenId  --where a.TaskId='CA83758E-9F6F-4376-88B1-E3B1703E011D'
group by a.TaskId,GroupName
 ) a left join  (
            select a.TaskId,count( distinct ForwardWechatOpenId) ClickUserCount
            from tblTaskFlowRecord a where a.OperationType=1                     
            group by a.TaskId 

) b on a.TaskId=b.TaskId left join(

             select TaskId,SUM(SecondShareScore) SecondShareScore
             from tblTaskFlowRecord  where OperationType=1 
             group by TaskId

             ) c on b.TaskId=c.TaskId                              
order by ShareCount desc
z1_23456 2018-12-04
  • 打赏
  • 举报
回复
max(c.GroupName) GroupName这个也没用,c.TaskId和c.OpenId都为null
select a.TaskId,max(c.GroupName) GroupName,
sum(case when OperationType=1 then 0 else 1 end) ShareCount,
sum(case when OperationType=1 then 1 else 0 end) ClickCount,SUM(ShareScore) ShareScore,
count( distinct ForwardWechatOpenId) JoinInUserCount
from tblTaskFlowRecord a left join tblTask b on a.TaskId=b.TaskId left join (

select a.TaskId,a.usergroupid,c.openid,e.GroupName from tblTaskRelationUserGroup a
left join tblUserGroupRelation b on a.UserGroupRelationId=b.UserGroupRelationId and b.IsDel=0
left join SysUser c on b.userid=c.userid
right join tblUserGroup e on e.UserGroupId = b.UserGroupId and e.IsDel = 0
)c on GroupName=c.GroupName and a.TaskId=c.TaskId and a.UseWechatOpenId=c.OpenId
group by a.TaskId

6,129

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 新技术前沿
社区管理员
  • 新技术前沿社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧