I need a query to Count distinct results…
My Table
ID | stats | name
-----------------
1 | 1 | John
2 | 1 | John
3 | 2 | John
4 | 2 | John
5 | 3 | John
i need query like this….
SELECT if( stats = 2, ADD + 1, 0) as ok, if(stats = 3, ADD + 1, 0) as no_ok
Thanks.
If you want to simultaneously count the number of rows with multiple specific criteria in a data set, you can use the pattern
COUNT(CASE WHEN criteria THEN 1 END). Here’s an example that counts the number of rows forstats = 2, and forstats = 3:Results:
Demo: http://www.sqlfiddle.com/#!2/82414/1