如何更改下面的脚本,以便我可以对 QTR_PCT 给出的值进行 GROUP BY YR、QTR、CODE 以获得所需的输出?
CREATE VIEW REPORTS.MY_VIEW
(YR, QTR, QTR_PCT, CODE)
AS
SELECT YR, QTR
, CASE WHEN PCTPERF>=85 THEN ROUND(AVG(PCTPERF))
ELSE NULL
END QTR_PCT
, CODE
FROM ANOTHER_VIEW
GROUP BY YR, QTR, PCTPERF, CODE
ORDER BY CODE ASC;
实际输出:(我没有包括 QTR_PCT 列)
+------+-----+------+
| YR | QTR | CODE |
+------+-----+------+
| 2012 | 1 | 1039 |
| 2012 | 1 | 1039 |
| 2012 | 1 | 1039 |
| 2012 | 2 | 1039 |
| 2012 | 2 | 1039 |
| 2012 | 2 | 1039 |
+------+-----+------+
期望的输出:(我没有包括列 QTR_PCT)
+------+-----+------+
| YR | QTR | CODE |
+------+-----+------+
| 2012 | 1 | 1039 |
| 2012 | 2 | 1039 |
+------+-----+------+