mysql where sum > 0 1

mysql where sum > 0

 SELECT user.id, CONCAT(lastname, firstname), year, month, date FROM user
LEFT JOIN adoption ON user.id = adoption.adopter
GROUP BY user.id
HAVING SUM(CONCAT(year,month,date) = '2016618') = 0

Here is what the above code is Doing:
1. Selecting the user.id, lastname, firstname, year, month, date from the user table
2. Joining the adoption table to the user table on the adopter column
3. Grouping the results by user.id
4. Having the sum of the concatenated year, month, date equal to 2016618

The above code will return all users who have not adopted a dog on June 18, 2016.

Similar Posts