查询:对于经过超过三架飞机认证的每位飞行员,找到他/她认证的每架飞机的开斋节和最大巡航范围。
查询我写道:
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;
输出:
它仅显示一个巡航范围,但 id 10 的飞行员已通过 4架飞机认证。如何获得其他行?
答案 0 :(得分:2)
你的问题实际上分为两部分:
找到经过三架以上飞机认证的飞行员
Dictionary<string,decimal> packageDict= new Dictionary<string,decimal>();
packageDict.AddKeyIfNotExists("demoKey",500);//will add in dictionary
packageDict.AddKeyIfNotExists("demoKey1", 200);//will add in dictionary
packageDict.AddKeyIfNotExists("demoKey", 6);//will not add in dictionary
查找这些飞机的续航范围
SELECT eid FROM certified GROUP BY eid HAVING COUNT(*) > 3
结合两者:
SELECT eid, cruising_range FROM aircraft JOIN certified USING (aid) ...
答案 1 :(得分:0)
使用group by certified.eid
。
count是一个聚合运算符,只返回一行 (没有分组条款)
select certified.eid,cruising_range
from certified join employee
on employee.eid=certified.eid
join aircraft
on certified.aid=aircraft.aid
group by certified.eid`
having count(certified.eid)>3;
没有group by aggregate函数只返回一行