Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL select if count

i have two tables Incident (id, date) Reminder (incidentID, type) inner join on incident.id = reminder.incidentID

and i want to take incident.id only if it has more than 4 reminder.type = 15 what i think is

SELECT incident.id
FROM incident
INNER JOIN reminder ON incident.id = reminder.incidentid 
HAVING COUNT (reminder.remindertype = "something") >5
GROUP BY incident.incidentcode

The erroe i get is

Line 6: Incorrect syntax near '='.

What can i do?

like image 845
Land Rover Avatar asked Apr 02 '13 13:04

Land Rover


1 Answers

COUNT doesn't work like that.

Try:

select incident.id
from incident
inner join reminder
on incident.id = reminder.incidentid
WHERE reminder.remindertype = "something"
group by incident.incidentcode 
having count (reminder.remindertype) >5
like image 160
Darren Avatar answered Sep 25 '22 06:09

Darren