• 比较好的SQL


    DECLARE @Data NVARCHAR(30);
    DECLARE @Data2 NVARCHAR(30);
    SET @Data = @DataDate;
    SET @Data = CONVERT(CHAR(30), DATEADD(HOUR, 8, @Data), 120);
    SET @Data2 = CONVERT(CHAR(30), DATEADD(day, 1, @Data), 120);
    DELETE FROM dbo.WF_ActionSummary
    WHERE ActionDate = CONVERT(CHAR(10), @Data, 120);
    INSERT INTO dbo.WF_ActionSummary
    ( ActionDate ,
    ActionType ,
    ActionCode ,
    CountryCode ,
    DeliveryCode ,
    ActionComplex ,
    JobNumber ,
    ActionNumber
    )
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'PS' 动作分类 ,
    ActionCode 动作类别 ,
    '' 国家 ,
    '' 渠道 ,
    DifficultyLevel 动作复杂度 ,
    MAX(b.JobNumber) 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE ActionTime > @Data
    AND a.ActionCode = 'CKI'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY DifficultyLevel ,
    a.ActionUser ,
    ActionCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'GP' 动作分类 ,
    'SRT' 动作类别 ,
    '' 国家 ,
    '' 渠道 ,
    1 动作复杂度 ,
    '' 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    WHERE ActionTime > @Data
    AND a.ActionCode = 'CKI'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'GP' 动作分类 ,
    'CK2' 动作类别 ,
    CountryCode 国家 ,
    '' 渠道 ,
    1 动作复杂度 ,
    '' 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE ActionTime > @Data
    AND a.ActionCode = 'CKI'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY CountryCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'PS' 动作分类 ,
    ActionCode 动作类别 ,
    CountryCode 国家 ,
    '' 渠道 ,
    DifficultyLevel 动作复杂度 ,
    MAX(b.JobNumber) 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE ActionTime > @Data
    AND a.ActionCode = 'PAW'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY CountryCode ,
    DifficultyLevel ,
    a.ActionUser ,
    ActionCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'PS' 动作分类 ,
    ActionCode 动作类别 ,
    CountryCode 国家 ,
    '' 渠道 ,
    DifficultyLevel 动作复杂度 ,
    MAX(b.JobNumber) 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE ActionTime > @Data
    AND a.ActionCode = 'MGL'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY CountryCode ,
    DifficultyLevel ,
    a.ActionUser ,
    ActionCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'PS' 动作分类 ,
    ActionCode 动作类别 ,
    CountryCode 国家 ,
    '' 渠道 ,
    DifficultyLevel 动作复杂度 ,
    MAX(b.JobNumber) 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE ActionTime > @Data
    AND a.ActionCode = 'PIK'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY CountryCode ,
    DifficultyLevel ,
    a.ActionUser ,
    ActionCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'PS' 动作分类 ,
    ActionCode 动作类别 ,
    CountryCode 国家 ,
    '' 渠道 ,
    1 动作复杂度 ,
    MAX(b.JobNumber) 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE ActionTime > @Data
    AND a.ActionCode = 'CHK'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY CountryCode ,
    a.ActionUser ,
    ActionCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'GP' 动作分类 ,
    'PKG' 动作类别 ,
    CountryCode 国家 ,
    DeliveryCode 渠道 ,
    1 动作复杂度 ,
    '' 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE ActionTime > @Data
    AND a.ActionCode = 'PIK'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY CountryCode ,
    DeliveryCode ,
    ActionCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'PS' 动作分类 ,
    ActionCode 动作类别 ,
    '' 国家 ,
    '' 渠道 ,
    1 动作复杂度 ,
    MAX(b.JobNumber) 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE ActionTime > @Data
    AND a.ActionCode = 'PRL'
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY a.ActionUser ,
    ActionCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'GP' 动作分类 ,
    'ZON' 动作类别 ,
    CountryCode 国家 ,
    DeliveryCode 渠道 ,
    1 动作复杂度 ,
    '' 操作员工 ,
    COUNT(0) 动作数量
    FROM dbo.WF_ActionInstance a WITH ( NOLOCK )
    INNER JOIN [Tr.TWX.WebFrame].dbo.Adm_User b WITH ( NOLOCK ) ON a.ActionUser = b.UserID
    WHERE a.ActionCode = 'PIK'
    AND ActionTime > @Data
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    AND DeliveryCode <> '0'
    GROUP BY CountryCode ,
    DeliveryCode ,
    ActionCode
    UNION ALL
    SELECT CONVERT(CHAR(10), @Data, 120) AS 动作日期 ,
    'GP' 动作分类 ,
    'BAG' 动作类别 ,
    CountryCode 国家 ,
    DeliveryCode 渠道 ,
    1 动作复杂度 ,
    '' 操作员工 ,
    COUNT(0) 动作数量
    FROM WF_ActionInstance a WITH ( NOLOCK )
    WHERE ActionCode = 'BAG'
    AND ActionTime > @Data
    AND ActionTime < @Data2
    AND a.DeleteUser = 0
    GROUP BY CountryCode ,
    DeliveryCode

  • 相关阅读:
    springboot mybatis-plus 多数据源
    怎样建网站?
    哪些软件外包公司为什么不赚钱?
    初高中英语 牛津书虫全套系列 英汉双语读物系列1-6级 音频+文本网盘下载【收藏】
    英语零基础直达六级水平-英语学习全能套装视频完整版【收藏】
    重构:改善既有代码的设计(第2版)(pdf,epub,azw3,mobi)[收藏]
    彻底关闭浏览器的弹出广告或通知(Chrome+Firefox )
    《读者》杂志38年合集 (1981-2018)电子版【收藏】
    怎样在知乎赚钱?(知乎好物)
    《故事会》(2010-2019)全年合集pdf版 [收藏]
  • 原文地址:https://www.cnblogs.com/chengjun/p/8651767.html
Copyright © 2020-2023  润新知