0

以下是数据库说明:

公司(ID_comp,名称)

旅行(trip_no,id_comp,飞机,town_from,town_to,time_out,time_in)

乘客(ID_psg,姓名)

Pass_in_trip(trip_no, date, ID_psg, place)

  • 公司表有运输乘客的公司的 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)
4

3 回答 3

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(*) ;
于 2013-10-09T06:50:12.090 回答
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  
于 2015-04-21T06:13:30.940 回答
0
with pascounts as
( select id_psg, place, count(*)
  from pass_in_trip
  group by id_psg, place
  having count(*) > 1 )
select name 
from passenger as a
inner join pascounts as b
on a.id_psg = b.id_psg
于 2021-01-07T09:25:31.997 回答