| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2090 人关注过本帖
标题:有人能帮忙翻译这段SQL语法吗?
只看楼主 加入收藏
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
结帖率:95.56%
收藏
已结贴  问题点数:20 回复次数:5 
有人能帮忙翻译这段SQL语法吗?
SELECT ROW_NUMBER() OVER (ORDER BY ProjectType, DepartmentNo, KickOffDate DESC, ProjectNo DESC) AS RowNo, * FROM
(SELECT A.ProjectNo, A.ProjectType, A.DevpType, A.KickOffDate, A.DeviceNo AS DeviceName, A.RequestService, A.Platform01, A.Platform02, A.Platform03, A.ProductType,
CASE WHEN ISNULL(A.NPINumber, 'NK') = 'NK' THEN 'NK' ELSE 'N' END AS NPIType, A.SalesNo, A.EstFinishDate AS
PlanDate, A.Remark, A.Div, A.DepartmentNo, A.EngineerNo, A.ReleaseStatus, A.ReleaseStatusDate, A.PhaseDate, B.StatusDesc AS
ReleaseName, C.StatusDesc AS PhaseName, D.CustomerEngSName, D.CustomerChiSName, '' AS SubRev, NULL AS SubRevNo FROM tblProject AS A
INNER JOIN tblBasStatusDesc AS B ON A.ReleaseStatus = B.Status AND B.Category = 'ProjectReleaseStatus'
LEFT OUTER JOIN tblBasStatusDesc AS C ON A.Phase = C.Status AND C.Category = 'ProjectPhase'
LEFT OUTER JOIN tblMstCustomerPublic AS D ON A.CustomerNo = D.CustomerNo WHERE A.SubDevFlag = 'N' AND A.DevpType
IN ('TD开发', '客户开发') AND ((A.KickOffDate >= '2020/04/26' AND A.KickOffDate < '2020/05/03') OR (A.ReleaseStatusDate >= '2020/ 04/26' AND
A.ReleaseStatusDate < '2020/05/03') OR (A.KickOffDate < '2020/05/03' AND A.ReleaseStatus < 3) OR
(A.KickOffDate < '2020/04/26' AND A.ReleaseStatus >= 3 AND A.ReleaseStatusDate >= '2020/05/03' AND A.ReleaseStatusDate < '2020/05/09'))
UNION ALL
SELECT B.ProjectNo, B.ProjectType, B.DevpType, A.ItemDate AS KickOffDate, A.DeviceName, B.RequestService, B.Platform01, B.Platform02, B.Platform03, B.ProductType,
CASE WHEN ISNULL(B.NPINumber, 'NK') = 'NK' THEN 'NK' ELSE 'N' END AS NPIType, B.SalesNo, B.EstFinishDate AS
PlanDate, B.Remark, B.Div, B.DepartmentNo, B.EngineerNo, A.ReleaseStatus, A.ReleaseStatusDate, A.PhaseDate, C.StatusDesc AS
ReleaseName, D.StatusDesc AS PhaseName, E.CustomerEngSName, E.CustomerChiSName, 'S' AS SubRev, A.ItemNo AS SubRevNo FROM tblProjectSubDevice AS A
INNER JOIN tblProject AS B ON A.ProjectNo = B.ProjectNo AND B.SubDevFlag = 'Y'
INNER JOIN tblBasStatusDesc AS C ON A.ReleaseStatus = C.Status AND C.Category = 'ProjectReleaseStatus'
LEFT OUTER JOIN tblBasStatusDesc AS D ON A.Phase = D.Status AND D.Category = 'ProjectPhase'
LEFT OUTER JOIN tblMstCustomerPublic AS E ON B.CustomerNo = E.CustomerNo WHERE B.DevpType IN ('TD开发', '客户开发') AND
((A.ItemDate >= '2020/04/26' AND A.ItemDate < '2020/05/03') OR (A.ReleaseStatusDate >= '2020/04/26' AND
A.ReleaseStatusDate < '2020/05/03') OR (A.ItemDate < '2020/05/03' AND A.ReleaseStatus < 3) OR (A.ItemDate < '2020/04/26' AND A.ReleaseStatus > = 3
AND A.ReleaseStatusDate >= '2020/05/03' AND A.ReleaseStatusDate < '2020/05/09'))
UNION ALL
SELECT B.ProjectNo, B.ProjectType, B.DevpType, A.IndexDate AS KickOffDate, A.DeviceName, B.RequestService, B.Platform01, B.Platform02, B.Platform03, B.ProductType,
CASE WHEN ISNULL(B.NPINumber, 'NK') = 'NK' THEN 'NK' ELSE 'N' END AS NPIType, B.SalesNo, B.EstFinishDate AS
PlanDate, B.Remark, B.Div, B.DepartmentNo, B.EngineerNo, A.ReleaseStatus, A.ReleaseStatusDate, A.PhaseDate, C.StatusDesc AS
ReleaseName, D.StatusDesc AS PhaseName, E.CustomerEngSName, E.CustomerChiSName, 'R' AS SubRev, A.IndexNo AS SubRevNo FROM tblProjectRevision AS A
INNER JOIN tblProject AS B ON A.ProjectNo = B.ProjectNo
INNER JOIN tblBasStatusDesc AS C ON A.ReleaseStatus = C.Status AND C.Category = 'ProjectReleaseStatus'
LEFT OUTER JOIN tblBasStatusDesc AS D ON A.Phase = D.Status AND D.Category = 'ProjectPhase'
LEFT OUTER JOIN tblMstCustomerPublic AS E ON B.CustomerNo = E.CustomerNo WHERE B.DevpType IN ('TD开发', '客户开发') AND ((A.IndexDate >= '2020/04/26'
AND A.IndexDate < '2020/05/03') OR (A.ReleaseStatusDate >= '2020/04/26' AND A.ReleaseStatusDate < '2020/05/03') OR (A.IndexDate < '2020/05 /03' AND A.ReleaseStatus < 3) OR
(A.IndexDate < '2020/04/26' AND A.ReleaseStatus >= 3 AND A.ReleaseStatusDate >= '2020/05/03' AND A.ReleaseStatusDate < '2020/05/09')) ) AS myTable1

前人写的,太长实在看不懂,又很多一层又包一层的'()'搜寻指令,我已经稍微做些断行处理了,还是很难懂。
搜索更多相关主题的帖子: LEFT 开发 Status AND JOIN 
2020-05-08 12:36
厨师王德榜
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:199
帖 子:995
专家分:4966
注 册:2013-2-16
收藏
得分:20 
用UNION ALL分隔的,有三段,这三段拆开来看,每段都是一个独立的查询.
再看其中的一段, 分别以不同的条件,链接了tblBasStatusDesc\ tblMstCustomerPublic 2表
另外新生成的NPIType字段,用条件 CASE WHEN ISNULL(B.NPINumber, 'NK') = 'NK' THEN 'NK' ELSE 'N' END
作了一个限定,其它没什么可说的了,遇到长的查询语句不要慌,
尤其是用UNION ALL分隔的更不要慌乱,无非就是几个相同字段的查询联合起来,
把其中一段读懂了,后来就好办了.
说实话,你这个查询其实并不复杂.
2020-05-09 11:08
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
收藏
得分:0 
以下是引用厨师王德榜在2020-5-9 11:08:08的发言:

用UNION ALL分隔的,有三段,这三段拆开来看,每段都是一个独立的查询.
再看其中的一段, 分别以不同的条件,链接了tblBasStatusDesc\ tblMstCustomerPublic 2表
另外新生成的NPIType字段,用条件 CASE WHEN ISNULL(B.NPINumber, 'NK') = 'NK' THEN 'NK' ELSE 'N' END
作了一个限定,其它没什么可说的了,遇到长的查询语句不要慌,
尤其是用UNION ALL分隔的更不要慌乱,无非就是几个相同字段的查询联合起来,
把其中一段读懂了,后来就好办了.
说实话,你这个查询其实并不复杂.


虽然还是看不懂,不过感觉上好像很有道理。

不要投我
2020-05-14 15:17
sssooosss
Rank: 9Rank: 9Rank: 9
等 级:禁止访问
威 望:3
帖 子:664
专家分:1115
注 册:2019-8-27
收藏
得分:0 
一段段分析着慢慢看就明白了
2020-07-19 14:44
oldfish96
Rank: 2
等 级:论坛游民
威 望:1
帖 子:16
专家分:17
注 册:2020-7-24
收藏
得分:0 
用sql prompt格式化下
SELECT ROW_NUMBER() OVER ( ORDER BY ProjectType, DepartmentNo, KickOffDate DESC, ProjectNo DESC ) AS RowNo, *
    FROM( SELECT A.ProjectNo, A.ProjectType, A.DevpType, A.KickOffDate, A.DeviceNo AS DeviceName, A.RequestService,
                 A.Platform01, A.Platform02, A.Platform03, A.ProductType,
                 CASE WHEN ISNULL(A.NPINumber, 'NK') = 'NK' THEN 'NK' ELSE 'N' END AS NPIType, A.SalesNo,
                 A.EstFinishDate AS PlanDate, A.Remark, A.Div, A.DepartmentNo, A.EngineerNo, A.ReleaseStatus,
                 A.ReleaseStatusDate, A.PhaseDate, B.StatusDesc AS ReleaseName, C.StatusDesc AS PhaseName,
                 D.CustomerEngSName, D.CustomerChiSName, '' AS SubRev, NULL AS SubRevNo
              FROM tblProject AS A
                   INNER JOIN tblBasStatusDesc AS B ON A.ReleaseStatus = B.Status
                                                       AND B.Category = 'ProjectReleaseStatus'
                   LEFT OUTER JOIN tblBasStatusDesc AS C ON A.Phase = C.Status
                                                            AND C.Category = 'ProjectPhase'
                   LEFT OUTER JOIN tblMstCustomerPublic AS D ON A.CustomerNo = D.CustomerNo
              WHERE A.SubDevFlag = 'N'
                    AND A.DevpType IN ( 'TD开发', '客户开发' )
                    AND (( A.KickOffDate >= '2020/04/26' AND A.KickOffDate < '2020/05/03' )
                         OR ( A.ReleaseStatusDate >= '2020/ 04/26' AND A.ReleaseStatusDate < '2020/05/03' )
                         OR ( A.KickOffDate < '2020/05/03' AND A.ReleaseStatus < 3 )
                         OR ( A.KickOffDate < '2020/04/26'
                              AND A.ReleaseStatus >= 3
                              AND A.ReleaseStatusDate >= '2020/05/03'
                              AND A.ReleaseStatusDate < '2020/05/09' ))
          UNION ALL
          SELECT B.ProjectNo, B.ProjectType, B.DevpType, A.ItemDate AS KickOffDate, A.DeviceName, B.RequestService,
                 B.Platform01, B.Platform02, B.Platform03, B.ProductType,
                 CASE WHEN ISNULL(B.NPINumber, 'NK') = 'NK' THEN 'NK' ELSE 'N' END AS NPIType, B.SalesNo,
                 B.EstFinishDate AS PlanDate, B.Remark, B.Div, B.DepartmentNo, B.EngineerNo, A.ReleaseStatus,
                 A.ReleaseStatusDate, A.PhaseDate, C.StatusDesc AS ReleaseName, D.StatusDesc AS PhaseName,
                 E.CustomerEngSName, E.CustomerChiSName, 'S' AS SubRev, A.ItemNo AS SubRevNo
              FROM tblProjectSubDevice AS A
                   INNER JOIN tblProject AS B ON A.ProjectNo = B.ProjectNo
                                                 AND B.SubDevFlag = 'Y'
                   INNER JOIN tblBasStatusDesc AS C ON A.ReleaseStatus = C.Status
                                                       AND C.Category = 'ProjectReleaseStatus'
                   LEFT OUTER JOIN tblBasStatusDesc AS D ON A.Phase = D.Status
                                                            AND D.Category = 'ProjectPhase'
                   LEFT OUTER JOIN tblMstCustomerPublic AS E ON B.CustomerNo = E.CustomerNo
              WHERE B.DevpType IN ( 'TD开发', '客户开发' )
                    AND (( A.ItemDate >= '2020/04/26' AND A.ItemDate < '2020/05/03' )
                         OR ( A.ReleaseStatusDate >= '2020/04/26' AND A.ReleaseStatusDate < '2020/05/03' )
                         OR ( A.ItemDate < '2020/05/03' AND A.ReleaseStatus < 3 )
                         OR ( A.ItemDate < '2020/04/26'
                              AND A.ReleaseStatus >= 3
                              AND A.ReleaseStatusDate >= '2020/05/03'
                              AND A.ReleaseStatusDate < '2020/05/09' ))
          UNION ALL
          SELECT B.ProjectNo, B.ProjectType, B.DevpType, A.IndexDate AS KickOffDate, A.DeviceName, B.RequestService,
                 B.Platform01, B.Platform02, B.Platform03, B.ProductType,
                 CASE WHEN ISNULL(B.NPINumber, 'NK') = 'NK' THEN 'NK' ELSE 'N' END AS NPIType, B.SalesNo,
                 B.EstFinishDate AS PlanDate, B.Remark, B.Div, B.DepartmentNo, B.EngineerNo, A.ReleaseStatus,
                 A.ReleaseStatusDate, A.PhaseDate, C.StatusDesc AS ReleaseName, D.StatusDesc AS PhaseName,
                 E.CustomerEngSName, E.CustomerChiSName, 'R' AS SubRev, A.IndexNo AS SubRevNo
              FROM tblProjectRevision AS A
                   INNER JOIN tblProject AS B ON A.ProjectNo = B.ProjectNo
                   INNER JOIN tblBasStatusDesc AS C ON A.ReleaseStatus = C.Status
                                                       AND C.Category = 'ProjectReleaseStatus'
                   LEFT OUTER JOIN tblBasStatusDesc AS D ON A.Phase = D.Status
                                                            AND D.Category = 'ProjectPhase'
                   LEFT OUTER JOIN tblMstCustomerPublic AS E ON B.CustomerNo = E.CustomerNo
              WHERE B.DevpType IN ( 'TD开发', '客户开发' )
                    AND (( A.IndexDate >= '2020/04/26' AND A.IndexDate < '2020/05/03' )
                         OR ( A.ReleaseStatusDate >= '2020/04/26' AND A.ReleaseStatusDate < '2020/05/03' )
                         OR ( A.IndexDate < '2020/05 /03' AND A.ReleaseStatus < 3 )
                         OR ( A.IndexDate < '2020/04/26'
                              AND A.ReleaseStatus >= 3
                              AND A.ReleaseStatusDate >= '2020/05/03'
                              AND A.ReleaseStatusDate < '2020/05/09' ))) AS myTable1
2020-07-24 22:07
likeyou32
Rank: 2
等 级:论坛游民
帖 子:4
专家分:20
注 册:2020-8-14
收藏
得分:0 
谢谢,我也仔细研究下,刚开始学
2020-08-14 10:27
快速回复:有人能帮忙翻译这段SQL语法吗?
数据加载中...
 
   



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

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