#2
厨师王德榜2020-05-09 11:08
|
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
前人写的,太长实在看不懂,又很多一层又包一层的'()'搜寻指令,我已经稍微做些断行处理了,还是很难懂。