gpt4 book ai didi

sql - 如何按以下别名列分组

转载 作者:搜寻专家 更新时间:2023-10-30 22:07:50 25 4
gpt4 key购买 nike

在以下查询中,您将如何按别名列 Test_Quarter 进行分组:

SELECT  a.testID, 
a.projectYear ,
CASE a.ProjectPeriod
WHEN 1 THEN 1
WHEN 2 THEN 1
WHEN 3 THEN 1
WHEN 4 THEN 2
WHEN 5 THEN 2
WHEN 6 THEN 2
WHEN 7 THEN 3
WHEN 8 THEN 3
WHEN 9 THEN 3
WHEN 10 THEN 4
WHEN 11 THEN 4
WHEN 12 THEN 4
END AS Test_Quarter,
SUM(a.cost)
FROM test a
GROUP BY a.testID, a.projectYear, Test_Quarter

谢谢,

最佳答案

按子句在分组中包含案例陈述

SELECT  a.testID, 
a.projectYear ,
CASE a.ProjectPeriod
WHEN 1 THEN 1
WHEN 2 THEN 1
WHEN 3 THEN 1
WHEN 4 THEN 2
WHEN 5 THEN 2
WHEN 6 THEN 2
WHEN 7 THEN 3
WHEN 8 THEN 3
WHEN 9 THEN 3
WHEN 10 THEN 4
WHEN 11 THEN 4
WHEN 12 THEN 4
END AS Test_Quarter,
SUM(a.cost)
FROM test a
GROUP BY a.testID, a.projectYear, CASE a.ProjectPeriod
WHEN 1 THEN 1
WHEN 2 THEN 1
WHEN 3 THEN 1
WHEN 4 THEN 2
WHEN 5 THEN 2
WHEN 6 THEN 2
WHEN 7 THEN 3
WHEN 8 THEN 3
WHEN 9 THEN 3
WHEN 10 THEN 4
WHEN 11 THEN 4
WHEN 12 THEN 4
END

关于sql - 如何按以下别名列分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43938209/

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