我在下面的查询中收到错误,而我正在尝试对子查询进行分组。我使用WITH子句构建了子查询。
请纠正我
WITH Student AS (SELECT * FROM CLASS WHERE SEX='M')
SELECT NAME, AGE, STATUS, SUM(TOTAL)
(SELECT
NAME,
'15' AS AGE,
CASE WHEN ATTENDANCE > 50 AND ATTENDANCE < 60 THEN 'GOOD'
WHEN ATTENDANCE > 60 'GREAT'
ELSE 'BAD' END AS STATUS
SUM (MARK) AS TOTAL
FROM STUDENT
GROUP BY NAME, ATTENDANCE ) A
GROUP BY NAME, AGE, STATUS
错误:SQL Query not properly ended
答案 0 :(得分:1)
我认为您错过了from
条款:
WITH Student AS (SELECT * FROM CLASS WHERE SEX='M')
SELECT NAME, AGE, STATUS, SUM(TOTAL)
FROM (SELECT NAME, '15' AS AGE,
(CASE WHEN ATTENDANCE > 50 AND ATTENDANCE < 60 THEN 'GOOD'
WHEN ATTENDANCE > 60 'GREAT'
ELSE 'BAD'
END) AS STATUS,
SUM(MARK) AS TOTAL
FROM STUDENT
GROUP BY NAME, ATTENDANCE
) A
GROUP BY NAME, AGE, STATUS
查询比实现所需输出所需的时间长得多,但这似乎是你遇到的问题。