按子句查询分组,该子查询源自WITH CLAUSE

时间:2015-09-16 12:11:55

标签: sql oracle

我在下面的查询中收到错误,而我正在尝试对子查询进行分组。我使用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

1 个答案:

答案 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

查询比实现所需输出所需的时间长得多,但这似乎是你遇到的问题。