Oracle SQL- Getting "Distinct" values within a "CASE" query Oracle SQL- Getting "Distinct" values within a "CASE" query oracle oracle

Oracle SQL- Getting "Distinct" values within a "CASE" query


A simple test case for you to prove count(distinct ... returns only distinct values:

11:34:09 HR@vm_xe> select department_id, count(*) from employees group by department_id order by 2 desc;      DEPARTMENT_ID   COUNT(*)                                                                                      ------------- ----------                                                                                                 50         45                                                                                                 80         34                                                                                                100          6                                                                                                 30          6                                                                                                 60          5                                                                                                 90          3                                                                                                 20          2                                                                                                110          2                                                                                                 40          1                                                                                                 10          1                                                                                                             1                                                                                                 70          1                                                                                      12 rows selected.                                                                                             Elapsed: 00:00:00.03                                                                                          11:34:12 HR@vm_xe> select count(department_id) "ALL", count(distinct department_id) "DISTINCT" from employees;       ALL   DISTINCT                                                                                         ---------- ----------                                                                                                106         11                                                                                         1 row selected.                                                                                               Elapsed: 00:00:00.02                                                                                          11:34:20 HR@vm_xe>