需要来自数据库中多个类似DATA的单个数据

时间:2017-07-05 09:56:26

标签: sql

我想找出像这样的多个条目中显示的数据

5   296 19  7   887 DAAS    GAGO    {"password":""}     2017-06-24 13:33:15 2017-06-23 13:33:09 9   10  fuel        4   1   N125XP  DAAS    Requested
5   296 19  7   887 DAAS    GAGO    {"password":""}     2017-06-24 13:33:15 2017-06-23 13:33:09 9   10  fuel        4   1   N125XP  DAAS    Requested

我想看看这个数据一次怎么做? 我正在使用此Sql语句来执行此操作:

SELECT t1.trip_id, 
       t1.server_trip_id, 
       t1.aircraft_id,
       t2.flight_id,
       t3.server_fid,
       t3.dep,
       t3.dest,
       t3.service_provider,
       t3.flight_name,
       t3.sta,
       t3.std,
       t4.booking_id,
       t5.server_booking_id,
       t5.type,
       t5.trip_number,
       t5.company_id,
       t5.user_id,
       t5.aircraft_registration,
       t5.icao,
       t6.status
FROM trip t1 
    JOIN trip_flight t2 ON t2.trip_id = t1.trip_id
    JOIN flight t3 ON t3.fid = t2.flight_id
    JOIN trip_flight_booking t4 ON t4.flight_id = t2.flight_id
    JOIN booking t5 ON t5.booking_id = t4.booking_id OR t5.booking_id != t4.booking_id
    JOIN booking_status t6 ON t6.booking_id = t5.booking_id OR t6.booking_id != t5.booking_id
where t1.aircraft_id="19"

1 个答案:

答案 0 :(得分:0)

你确定你的联接是正确的......这似乎匹配任何一行;

t5.booking_id = t4.booking_id OR t5.booking_id != t4.booking_id

因为你有=或!=具有相同的值....

那就是说,你可以使用DISTINCT

SELECT DISTINCT t1.trip_id , t1.server_trip_id, t1.aircraft_id,
t2.flight_id,
t3.server_fid,t3.dep,t3.dest,t3.service_provider,t3.flight_name,t3.sta,t3.std,
t4.booking_id,
t5.server_booking_id,t5.type,t5.trip_number,t5.company_id,t5.user_id,t5.aircraft_registration,t5.icao,
t6.status
    FROM trip t1 
    JOIN trip_flight t2 ON t2.trip_id = t1.trip_id
    JOIN flight t3 ON t3.fid = t2.flight_id
    JOIN trip_flight_booking t4 ON t4.flight_id = t2.flight_id
    JOIN booking t5 ON t5.booking_id = t4.booking_id OR t5.booking_id != t4.booking_id
    JOIN booking_status t6 ON t6.booking_id = t5.booking_id OR t6.booking_id != t5.booking_id
    where t1.aircraft_id="19"