For the last few days I have been attempting to find a method to pull a very important set of information from a table that contains what I call daily counts. I have a table that is setup as follows.
person|company|prod1|prod2|prod3|gen_date
Each company has more than one person, and each person can have different combinations of products that they have purchased. What I have been trying to figure out is a SQL statement that will list the number of people that have bought a particular product per company. So an output similar to this:
Comp ABC | 13 Prod1 | 3 Prod2 | 5 Prod 3
Comp DEF | 2 Prod1 | 15 Prod2 | 0 Prod 3
Comp HIJ | 0 Prod1 | 0 Prod2 | 7 Prod 3
Currently if a person did not select a product the value being stored is NULL
.
Best I have right now is 3 different statements that can produce this information if run on their own.
SELECT Count(person) as puchases, company
FROM Sales WHERE prod1 = '1' and gendate = '3/24/2010'
Group BY company