I have been tasked to find all drugs (NDC) within a pharmacy database that are used exclusively by an array of customer IDs but not others. Basically find drugs that have no overlap between customers (array) so that we can trim unneeded inventory used by previous customers. Columns needed are NDC (drug code), DrugName.
Asked
Active
Viewed 51 times
0
-
2Please provide (add to your question) a representative data sample and the desired result. – PM 77-1 May 28 '21 at 13:37
-
Make it easy, and possible, to assist you: [mcve]. – jarlh May 28 '21 at 15:00
1 Answers
0
Hmmm . . .
select NDC, DrugName
from t
group by NDC, DrugName
having sum(case when customerid in ( . . . ) then 1 else 0 end) = 0;

Gordon Linoff
- 1,242,037
- 58
- 646
- 786