Lets say I have this SQL Table
id | name | date
1 | as | 0000-00-00
1 | df | 0000-00-00
1 | fg | 0000-00-00
1 | hj | 0000-00-00
2 | xc | 2011-2-32
2 | op | 2011-3-21
3 | er | 2011-2-43
4 | po | 0000-00-00
4 | ui | 0000-00-00
I want to get the id that has 4 rows of date which has a value of 0000-00-00, which would be 1
The SQL statement Im thinking of is something like this... (This is obviously wrong)
SELECT id
FROM table1
WHERE COUNT(date = 0000-00-00) = 4
I'm open to other answers in case you have a better/efficient solution
SELECT id, count(*)
FROM table1
WHERE date = 0000-00-00
GROUP BY id
HAVING count(*) = 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With