桌子:
+-----+----+----------+
| QTR | MO | PCT_PERF |
+-----+----+----------+
| 1 | 1 | 89 |
| 1 | 2 | 73 |
| 1 | 3 | 95 |
+-----+----+----------+
什么是正确的语法?
CASE WHEN QTR=1 THEN ROUND(SUM(PCT_PERF WHERE MO IN (1,2,3))/3,2)
WHEN QTR=2 THEN ROUND(SUM(PCT_PERF WHERE MO IN (4,5,6))/3,2)
WHEN QTR=3 THEN ROUND(SUM(PCT_PERF WHERE MO IN (7,8,9))/3,2)
ELSE ROUND(SUM(PCT_PERF WHERE MO IN (10,11,12))/3,2) END QTR_PCT
因此当 QTR 为 1 时,QTR_PCT 应为 86。 (89+73+95)/3 = 85.67