如何按以下查询对别名列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
谢谢,
答案 0 :(得分:2)
按条款
分组案例陈述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