我的查询我收到以下错误消息:
聚合可能不会出现在WHERE子句中,除非它位于HAVING子句或选择列表中包含的子查询中,并且要聚合的列是外部引用。
我的查询如下:
SELECT f.ID as IdFlight
From Flights as f
inner join BookingsFlightsPassenger as b on f.ID = b.ID_flight
WHERE count(b.ID_Flight)<100
我该如何解决这个问题?我不确定错误消息是什么意思
答案 0 :(得分:2)
替换&#34;其中&#34;通过&#34;有&#34;并按
添加分组SELECT f.ID as IdFlight
From Flights as f inner join BookingsFlightsPassenger as b on f.ID = b.ID_flight
group by f.id
having count(b.ID_Flight)<100
答案 1 :(得分:0)
编写此查询的最有效方法是不使用join
:
SELECT bfp.ID_flight as as IdFlight
FROM BookingsFlightsPassenger bfp
GROUP BY bfp.ID_flight
WHERE count(*) < 100;