I'm using SQL Queries for the first time and learning it. I've got a table like this:
| yearName | productcompanyID |
|---|---|
| 2001 | ID 1 |
| 2001 | ID 1 |
| 2001 | ID 2 |
| 2001 | ID 1 |
| 2001 | ID 1 |
| 2002 | ID 1 |
| 2002 | ID 1 |
| 2002 | ID 2 |
| 2002 | ID 2 |
| 2003 | ID 2 |
And I would like to count how many times a productcompanyID appear but counting it only once for a year. (Sorry my English is not my language and I might not be clear)
What I mean, for the moment I've writtent this SQL:
SELECT DISTINCT(productcompanyid),
COUNT(productcompanyid)
FROM mydatabase
GROUP BY productcompanyid
And it gives me the result as ID 1: 6 and ID 2 : 4.
What I would like to have is ID 1 : 2 (as it appears at least once in year 2001 and year 2002) and ID 2: 3 (as it appears at least once in year 2001, year 2002 and year 2003)
Thanks for your help.
