Hi guys, I'll attempt to explain the thread a title a bit better. I am trying to identify the effects of using certain prescribed drugs when taken together. Sp I have 5 different drugs, let's say drug 1,2...etc and I need a way to group together all people who have only taken 1 (random) drug, all people who have taken 2 (random) drugs etc etc up to 5 (random) drugs. So explicit combinations of certain drugs do not matter just yet. I have a database for all patients, and I have separate tables for all people using a certain drug that are in the general database, so I have something like:
Code:
SELECT DISTINCT A.PERSON FROM
(SELECT DISTINCT PERSON FROM PBASE) A
LEFT JOIN
(SELECT DISTINCT PERSON FROM DRUG1) B
ON A.PERSON = B.PERSON
LEFT JOIN
SELECT DISTINCT PERSON FROM DRUG2) C
ON A.PERSON = C.PERSON
.
.
.
.
.
.
--and so on
So I'll end up with a table of 6 columns where the first is a list of the people in the general database, and the other 5 are columns where a "YES" is in the field if that person is on that particular drug.
Now the tricky part.....(well for me anyway)
I would like to add a 7th columns that counts all of the "YES" fields and gives me a total of the amount of drugs they have taken so that I get the entire combination of drugs they have been using.
Anyone have any suggestions how to do this? Hence the title of the thread being " adding +1 if "YES" "
Any help will be much appreciated!