search

Home  >  Q&A  >  body text

SQL Count() also requires 0

I only have one table and I want to count each entry of a tag starting from 0

Now I try this:

SELECT label, COUNT(start) AS Anzahl, user_id FROM datensammlung where (start='1') AND (user_id='1') GROUP BY label;

But the reward is only:

Label quantity User ID
1_Eating Spoon 20 1
1_Blow your nose 20 1

But I want this:

Label quantity User ID
1_Eating Spoon 20 1
1_Blow your nose 20 1
1_Telephone 0 1

P粉547362845P粉547362845260 days ago744

reply all(1)I'll reply

  • P粉668113768

    P粉6681137682024-04-07 12:09:57

    If all label 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;

    reply
    0
  • Cancelreply