以下是数据库说明:
公司(ID_comp,名称)
旅行(trip_no,id_comp,plane,town_from,town_to,time_out,time_in)
乘客(ID_psg,姓名)
Pass_in_trip(trip_no,date,ID_psg,place)
我们应该注意到,
以下是问题:
查找在同一座位上飞行不止一次的不同乘客的姓名。
我试过这个查询
select name from (
select id_psg, count(name) as total from (
select a.id_psg, name, date,place from passenger a join
pass_in_trip b on a.id_psg=b.id_psg order by a.id_psg, place
) as t1
group by t1.id_psg
) as a join passenger b on a.id_psg = b.id_psg
join pass_in_trip c on a.id_psg=c.id_psg
where total > 1
group by name,place
having count(place) >=2
order by name,place;
但它说:
Wrong
Your query produced correct result set on main database, but it failed test on second, checking database
* Wrong number of records (more by 8)
答案 0 :(得分:1)
SELECT
p.name
FROM
passenger AS p
JOIN
pass_in_trip AS pt
ON p.id_psg = pt.id_psg
GROUP BY
p.id_psg, p.pame
HAVING
COUNT(DISTINCT pt.place) < COUNT(*) ;
答案 1 :(得分:0)
select name, place, COUNT(name)as "no of trips"
from Passenger p
join Pass_in_trip pt
on p.ID_psg=pt.ID_psg join Trip t
on pt.trip_no=t.trip_no
group by name, place
having count(name) > 1
答案 2 :(得分:0)
DataFrame