gpt4 book ai didi

sql - 按底部的某个字符串排序,然后按不同列的字母顺序

转载 作者:行者123 更新时间:2023-12-04 04:41:19 24 4
gpt4 key购买 nike

我正在尝试订购查询,但没有得到所需的结果:

SELECT R.[Name] AS Project, ISNULL(P.[Name]+' - '+P.[Description], 'KanBan') AS Sprint, S.[Number] AS Story, T.[Name] AS Task,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 1 THEN D.[Hours] ELSE 0 END) AS Monday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 2 THEN D.[Hours] ELSE 0 END) AS Tuesday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 3 THEN D.[Hours] ELSE 0 END) AS Wednesday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 4 THEN D.[Hours] ELSE 0 END) AS Thursday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 5 THEN D.[Hours] ELSE 0 END) AS Friday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 6 THEN D.[Hours] ELSE 0 END) AS Saturday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 7 THEN D.[Hours] ELSE 0 END) AS Sunday
FROM DailyTaskHours D
INNER JOIN Task T ON D.TaskId = T.PK_Task
INNER JOIN Story S ON T.StoryId = S.PK_Story
LEFT JOIN Sprint P ON S.SprintId = P.PK_Sprint
INNER JOIN Product R ON S.ProductId = R.PK_Product
GROUP BY R.[Name], P.[Name], P.[Description], S.[Number], T.[Name]
ORDER BY CASE WHEN (P.[Name]+' - '+P.[Description]) = 'KanBan' then 1 else 0 end, Project ASC, Story ASC, Task ASC

首先,我想要 P.[Name]+' - '+P.[Description] 为 NULL 并且用“KanBan”填充到底部,然后按产品的字母顺序排列,然后在产品后冲刺,然后是故事,然后是任务。

我怎样才能做到这一点?

编辑:谢谢这里是最后的查询:
SELECT R.[Name] AS Project, ISNULL(P.[Name]+' - '+P.[Description], 'KanBan') AS Sprint, S.[Number] AS Story, T.[Name] AS Task,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 1 THEN D.[Hours] ELSE 0 END) AS Monday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 2 THEN D.[Hours] ELSE 0 END) AS Tuesday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 3 THEN D.[Hours] ELSE 0 END) AS Wednesday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 4 THEN D.[Hours] ELSE 0 END) AS Thursday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 5 THEN D.[Hours] ELSE 0 END) AS Friday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 6 THEN D.[Hours] ELSE 0 END) AS Saturday,
sum(CASE WHEN DatePart(dw, D.ActivityDate) = 7 THEN D.[Hours] ELSE 0 END) AS Sunday
FROM DailyTaskHours D
INNER JOIN Task T ON D.TaskId = T.PK_Task
INNER JOIN Story S ON T.StoryId = S.PK_Story
LEFT JOIN Sprint P ON S.SprintId = P.PK_Sprint
INNER JOIN Product R ON S.ProductId = R.PK_Product
GROUP BY R.[Name], P.[Name], P.[Description], S.[Number], T.[Name]
ORDER BY CASE WHEN ISNULL(P.[Name]+' - '+P.[Description], 'KanBan') = 'KanBan'
THEN 1
ELSE 0 END,
Project ASC,
Sprint ASC,
Story ASC,
Task ASC

最佳答案

只需要稍微修改一下:

ORDER BY CASE WHEN ISNULL(P.[Name]+' - '+P.[Description], 'KanBan') = 'KanBan'
THEN 0
ELSE 1 END

问题是您永远不会收到 KanBan在您的 ORDER BY条款。

关于sql - 按底部的某个字符串排序,然后按不同列的字母顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18852800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com