I'm trying to get pretty basic output that pulls unique NDC Codes for medications and counts the number of unique patients that take each drug. My dataset basically looks like this:
patient_id | drug_ndc
---------------------
01 | 250
02 | 725
03 | 1075
04 | 1075
05 | 250
06 | 250
I want the output to look something like this:
NDC | Patients
--------------
250 | 3
1075 | 2
725 | 1
I tried using some queries like this:
select distinct drug_ndc as NDC, count patient_id as Patients
from table 1
group by 1
order by 1
But I keep getting errors. I've tried with and without using an alias, but to no avail.