Home > database >  How to count notifications with a certain status and a certain user_id?
How to count notifications with a certain status and a certain user_id?

Time:01-26

enter image description here How to count notifications with a certain status and a certain user_id ? I have some data in notification table, how is the logic to calculate notification whose status is field 3 based on user_id 2 ? I want to issue a total of 3 notifications with a status field of 3 in user_id 2

CodePudding user response:

calculate notification whose status is field 3 based on user_id 2

According to what you asked, the where condition is status field 3 based on user_id 2.

So you can do in this way

SELECT COUNT(*) FROM tablename WHERE status = 3 AND user_id = 2

Please show us your effort next time. Thank you

CodePudding user response:

You are searching for the group by function.

For all users and statuses:

SELECT COUNT(user_id), user_id, status FROM {Insert your table name} GROUP BY user_id, status ORDER BY user_id ASC;
  • Related