Home > Mobile >  HAVING COUNT statement
HAVING COUNT statement

Time:10-30

SELECT e.user_id
FROM event e
GROUP BY e.user_id
HAVING COUNT(e.action = 'like') = 0 AND COUNT(e.action = 'comment') = 0

I want to select the user ids that do not have any action in 'like' and 'comment'. However, seems the last line of the code does not work. Could someone suggest some modification? Thanks!

CodePudding user response:

Use SUM

SELECT e.user_id
FROM event e
GROUP BY e.user_id
HAVING SUM(e.action = 'like') = 0 AND SUM(e.action = 'comment') = 0

CodePudding user response:

Use Where Clause & NOT IN Operator.

SELECT e.user_id
FROM event e
Where Not e.action IN ('like', 'comment')
  • Related