【发布时间】:2021-01-07 17:25:31
【问题描述】:
这是数据库说明:
公司(ID_comp,名称)
Trip(trip_no, id_comp, plane, town_from, town_to, time_out, time_in)
乘客(ID_psg,姓名)
Pass_in_trip(trip_no, date, ID_psg, place)
- Company 表有运送乘客的公司的 ID 和名称。
- 行程表包含有关行程的信息:行程号、公司 ID、飞机类型、出发城市、到达城市、出发时间和到达时间。
- 乘客表包含乘客 ID 和乘客姓名。
- Pass_in_trip 表包含有关航班的信息:行程号、出发日期(天)、乘客的 ID 和他在飞行中的位置。
我们应该注意到,
- 每天都在完成任何旅行;飞行时间少于一个日历日(24 小时);
- 时间和日期被认为是一个相对的时区;
- 出发时间和到达时间都在一分钟内给出;
- 可能有同名乘客(例如 Bruce Willis);
- 飞行中的地点是一个数字后跟一个字母;数字定义行号,字母 (a - d) - 按字母顺序(从左到右)在行中的位置;
- 关系和限制显示在数据架构中。
这是一个问题:
找出在同一个座位上多次飞行的不同乘客的姓名。
我试过这个查询
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)
- 这是来自SQL-RU btw 的练习。
【问题讨论】:
标签: sql postgresql subquery