首页 > 代码库 > SQL LEN() 函数 ,case when,聚合函数的使用方法
SQL LEN() 函数 ,case when,聚合函数的使用方法
SELECT aa.[User_Id],cc.[User_Name],dd.Name AS DepName,aa.Module_Id,aa.Module_Name,
SUM(CASE aa.Operate_Type WHEN ‘2‘ THEN OperateNum END ) AS ‘AddNum‘,
SUM(CASE aa.Operate_Type WHEN ‘3‘ THEN OperateNum END ) AS ‘EditNum‘ ,
SUM(CASE aa.Operate_Type WHEN ‘4‘ THEN OperateNum END ) AS ‘DelNum‘
FROM (
SELECT a.[User_Id],a.Module_Id,c.Module_Name,a.Operate_Type,COUNT(1) AS OperateNum FROM dbo.Sys_User_Log AS a
INNER JOIN dbo.Sys_Module AS c ON a.Module_Id = c.Module_Id
WHERE LEN(a.Module_Id) = 6 AND (a.Operate_Type =‘2‘ OR a.Operate_Type =‘3‘ OR a.Operate_Type =‘4‘)//LEN() 函数
GROUP BY a.[User_Id],a.Module_Id,c.Module_Name,a.Operate_Type
) AS aa
INNER JOIN dbo.Sys_User AS cc ON aa.[User_Id] = cc.[User_Id]
INNER JOIN dbo.Sys_DepInfo AS dd ON cc.DepInfo_Id = dd.Id
GROUP BY aa.[User_Id],cc.[User_Name],dd.Name,aa.Module_Id,aa.Module_Name
ORDER BY aa.[User_Id],aa.Module_Id
SUM(CASE aa.Operate_Type WHEN ‘2‘ THEN OperateNum END ) AS ‘AddNum‘,
SUM(CASE aa.Operate_Type WHEN ‘3‘ THEN OperateNum END ) AS ‘EditNum‘ ,
SUM(CASE aa.Operate_Type WHEN ‘4‘ THEN OperateNum END ) AS ‘DelNum‘
FROM (
SELECT a.[User_Id],a.Module_Id,c.Module_Name,a.Operate_Type,COUNT(1) AS OperateNum FROM dbo.Sys_User_Log AS a
INNER JOIN dbo.Sys_Module AS c ON a.Module_Id = c.Module_Id
WHERE LEN(a.Module_Id) = 6 AND (a.Operate_Type =‘2‘ OR a.Operate_Type =‘3‘ OR a.Operate_Type =‘4‘)//LEN() 函数
GROUP BY a.[User_Id],a.Module_Id,c.Module_Name,a.Operate_Type
) AS aa
INNER JOIN dbo.Sys_User AS cc ON aa.[User_Id] = cc.[User_Id]
INNER JOIN dbo.Sys_DepInfo AS dd ON cc.DepInfo_Id = dd.Id
GROUP BY aa.[User_Id],cc.[User_Name],dd.Name,aa.Module_Id,aa.Module_Name
ORDER BY aa.[User_Id],aa.Module_Id
SQL LEN() 函数 ,case when,聚合函数的使用方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。