gpt4 book ai didi

mysql - 如何取消MySQL中having子句的组效应?

转载 作者:行者123 更新时间:2023-11-29 07:21:16 26 4
gpt4 key购买 nike

enter image description here

enter image description here

查询:对于每个获得超过三架飞机认证的飞行员,查找他/她获得认证的每架飞机的 eid 和最大巡航范围。

我写的查询:

select certified.eid,cruising_range
from certified join employee
on employee.eid=certified.eid
join aircraft
on certified.aid=aircraft.aid
having count(certified.eid)>3;

输出:

enter image description here

它仅显示一个巡航范围,但id 10的飞行员拥有4架飞机的认证。如何获取其他行?

最佳答案

您的问题实际上分为两部分:

  1. 查找获得三架以上飞机认证的飞行员

    SELECT eid FROM certified GROUP BY eid HAVING COUNT(*) > 3
  2. 查找这些飞机的巡航范围

    SELECT eid, cruising_range FROM aircraft JOIN certified USING (aid) ...

将两者结合起来:

SELECT eid, cruising_range FROM aircraft JOIN certified USING (aid) JOIN (
SELECT eid FROM certified GROUP BY eid HAVING COUNT(*) > 3
) t USING (eid)

关于mysql - 如何取消MySQL中having子句的组效应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36081123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com