我的问题之前已得到解决,但我似乎无法对我的查询应用任何解决方案以使其正常工作。非常感谢一些指导。
我下面的当前查询返回这个数据集:
| Age | Count | 0-1 day 300 2-3 days 6000 3-4 days 100
SELECT(CASE WHEN time_dtm > SYSDATE -1 THEN '0-1 day'
WHEN time_dtm > SYSDATE -2 AND time_dtm < SYSDATE -1 THEN '1-2 days'
WHEN time_dtm > SYSDATE -3 AND time_dtm < SYSDATE -2 THEN '2-3 days'
WHEN time_dtm > SYSDATE -4 AND time_dtm < SYSDATE -3 THEN '3-4 days'
WHEN time_dtm > SYSDATE -5 AND time_dtm < SYSDATE -4 THEN 'Closed'
END) AS Age,
COUNT( * ) AS "Count"
FROM table_1
WHERE id IN (1,2,3)
GROUP BY (CASE WHEN time_dtm > SYSDATE -1 THEN '0-1 day'
WHEN time_dtm > SYSDATE -2 AND time_dtm < SYSDATE -1 THEN '1-2 days'
WHEN time_dtm > SYSDATE -3 AND time_dtm < SYSDATE -2 THEN '2-3 days'
WHEN time_dtm > SYSDATE -4 AND time_dtm < SYSDATE -3 THEN '3-4 days'
WHEN time_dtm > SYSDATE -5 AND time_dtm < SYSDATE -4 THEN 'Closed'
END)
ORDER BY (CASE WHEN time_dtm > SYSDATE -1 THEN '0-1 day'
WHEN time_dtm > SYSDATE -2 AND time_dtm < SYSDATE -1 THEN '1-2 days'
WHEN time_dtm > SYSDATE -3 AND time_dtm < SYSDATE -2 THEN '2-3 days'
WHEN time_dtm > SYSDATE -4 AND time_dtm < SYSDATE -3 THEN '3-4 days'
WHEN time_dtm > SYSDATE -5 AND time_dtm < SYSDATE -4 THEN 'Closed'
END)
但是,我希望它将零/空行显示为零,如下所示:
| Age | Count | 0-1 day 300 1-2 days 0 2-3 days 6000 3-4 days 100 Closed 0
我已经阅读了过去几天的各种回复:NVL、COALESCE、FULL/LEFT/RIGHT OUTER JOIN、LEFT/RIGHT JOINS、UNION ALL 等,其中没有一个有 CASE 语句并试图自己解决它但是!你必须知道什么时候停下来问路。