I just have one table and i want to count every entry for label where start is 0
right now i try it like this:
SELECT label, COUNT(start) AS Anzahl, user_id FROM datensammlung Where (start='1') AND (user_id='1') GROUP BY label;
But the return is only:
Label | Anzahl | UserId |
---|---|---|
1_Eating spoon | 20 | 1 |
1_Nose Blowing | 20 | 1 |
But i would like to have it like that:
Label | Anzahl | UserId |
---|---|---|
1_Eating spoon | 20 | 1 |
1_Nose Blowing | 20 | 1 |
1_phone | 0 | 1 |
CodePudding user response:
If all label
s are available in the table, you can use conditional aggregation:
SELECT label,
SUM(user_id = '1' AND start = '1') AS Anzahl
FROM datensammlung
GROUP BY label;