The mysql table that I’m using has a structure:
id | type | date
--------------------------------
101 | 1 | 2011-02-08
102 | 2 | 2011-02-08
103 | 2 | 2011-02-08
104 | 2 | 2011-02-07
105 | 1 | 2011-02-07
105 | 1 | 2011-02-07
What I want to do is create a query that will give the following result:
total type 1 | total type 2 | date
------------------------------------------------
1 | 2 | 2011-02-08
2 | 1 | 2011-02-07
I tried with following query but not getting the desired result
SELECT count(DISTINCT id) as total, date, type FROM my_table WHERE type !='0' GROUP BY date, type ORDER BY date DESC
How can I do that?
Thanks for all suggestions
Use:
I’m assuming the
typecolumn is numeric, not string based like the single quotes suggest. Change to suit if that’s not the case.