并且我想在事件发生时使用fact.id只有4个以上的提醒.type = 15 我认为是什么
SELECT incident.id
FROM incident
INNER JOIN reminder ON incident.id = reminder.incidentid
HAVING COUNT (reminder.remindertype = "something") >5
GROUP BY incident.incidentcode
我得到的错误是
第6行:'='附近的语法不正确。
我该怎么办?
答案 0 :(得分:2)
group by
子句应在having
子句
select incident.id
from incident
inner join reminder
on incident.id = reminder.incidentid
group by incident.incidentcode
having count (reminder.remindertype) >5
答案 1 :(得分:2)
COUNT
不能那样工作。
尝试:
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
答案 2 :(得分:1)
你很近:
select incident.id
from incident inner join
reminder
on incident.id = reminder.incidentid
group by incident.incidentcode
having sum(case when reminder.remindertype = "something" then 1 else 0 end) >5
您的原始语法在大多数SQL方言中都不起作用。您需要条件聚合。