我需要改变这一结果,但希望其将各栏重新排列为具体顺序。 命令如欲,应晚于星期一,应明天,今天,应周知
任何人都可以帮助
with cte AS (SELECT cl.Name,
SUM(CASE WHEN dbo.TruncateDate(CURRENT_TIMESTAMP) = dbo.TruncateDate(oi.RequiredByDate) THEN 1 Else 0 END) as DueToday
,SUM(CASE WHEN CURRENT_TIMESTAMP > oi.RequiredByDate THEN 1 ELSE 0 END) as PastDue
,SUM(CASE WHEN DATEADD(dd, DATEDIFF(dd, 0, oi.RequiredByDate), 0) = dateadd(day, datediff(day, 19000101 ,CURRENT_TIMESTAMP), 19000102 ) then 1 ELSE 0 END) as DueTomorrow
,SUM(CASE WHEN DateDiff(day, getdate(), RequiredByDate) BETWEEN 2 and 7 AND DateName(weekday, RequiredByDate) = Monday Then 1 ELSE 0 END) as DueMonday
,SUM(CASE WHEN dbo.TruncateDate(CURRENT_TIMESTAMP) <= dbo.TruncateDate(oi.RequiredByDate) THEN 1 ELSE 0 END) as DueBeyond
FROM OrderItems oi
JOIN Orders o ON o.OrderID = oi.OrderID
JOIN Counties c ON c.FIPS = o.FIPS
JOIN Clients cl ON cl.ClientID = o.ClientID
JOIN Milestones m ON m.MilestoneID = oi.LastMilestoneID
JOIN Products p ON p.ProductID = oi.ProductID
JOIN Vendors v ON v.VendorID = oi.VendorID
LEFT JOIN ClientBranches clb ON clb.ClientID = o.ClientID
WHERE QueueID > 0 AND cl.Name NOT LIKE TES%
AND cl.NAME LIKE HLC%
GROUP BY cl.Name
)
Select * FROM cte