I have a table like this from which I want to count of recurrences per Username. I would like to count how many distinct Type are there with Amount <> 0 per user:
+----------+-------------+--------+
| Username | Type | Amount |
+----------+-------------+--------+
| abc | New | 1 |
| abc | New | 1 |
| abc | Old | 1 |
| def | New | 1 |
| def | Old | 0 |
| def | Refurbished | 1 |
| ijk | New | 1 |
| ijk | Old | 2 |
| ijk | Refurbished | 3 |
+----------+-------------+--------+
My result should look something like this:
+----------+---------------+
| Username | DistinctCount |
+----------+---------------+
| abc | 2 |
| def | 2 |
| ijk | 3 |
+----------+---------------+
..where [Username] abc has 2 distinct [Type] with [Amount] not equal to 0.
I have tried SELECT DISTINCT Type, Username, SUM(CASE WHEN Amount <> 0 THEN 1 ELSE 0 END) FROM tblBase GROUP BY Type, Username but it's not yielding the desired result.