Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 10.50 KB | None | 0 0
  1. SELECT * FROM ( SELECT x.*, c.flightRange,c.idcitypairs,
  2.                                          (SELECT idtasks_fmg FROM tasks_fmg WHERE tasks_fmg.rotationId = x.rotationId AND STA BETWEEN DATE_SUB(CAST('2019-12-06' AS DATE), INTERVAL 3 DAY) AND DATE_ADD(CAST('2019-12-06' AS DATE), INTERVAL 31 DAY) ORDER BY idtasks_fmg DESC LIMIT 0, 1) as idtasks_fmg,
  3.                                           tango.IDTangoHistory IDTangoHistoryInbound,
  4.                                           tangoOutbound.IDTangoHistory IDTangoHistoryOutbound
  5.                                                FROM ( SELECT
  6.                                                     LEFT(inbound.atcCallsign, 3) acOwner,
  7.                                                     inbound.acRegistration,
  8.                                                     inbound.dataVersion,
  9.                                                     inbound.flightId fFlightId,
  10.                                                     inbound.rotationId rotationId,
  11.                                                     inbound.rotationSegment fRotationSegment,
  12.                                                     REPLACE(inbound.iataFlightNumber,'  ',' ') fFlight,
  13.                                                     inbound.originDestination DEP,
  14.                                                     inbound.stand fStand,
  15.                                                     inbound.scheduledTime STA,
  16.                                                     inbound.internalTime ITA,
  17.                                                     inbound.blockTime ONB,
  18.                                                     inbound.actualTime fAT,
  19.                                                     inbound.acType,
  20.                                                     inbound.acTypeVersion,
  21.                                                     outbound.flightId nFlightId,
  22.                                                     outbound.rotationSegment nRotationSegment,
  23.                                                     REPLACE(outbound.iataFlightNumber,'  ',' ') nFlight,
  24.                                                     outbound.originDestination ARR,
  25.                                                     outbound.stand nStand,
  26.                                                     outbound.scheduledTime STD,
  27.                                                     outbound.internalTime ITD,
  28.                                                     outbound.blockTime OFB,
  29.                                                     outbound.actualTime nAT,
  30.                                                     NULL cleanType,
  31.                                                     NULL catType,
  32.                                                     CAST(inbound.scheduledTime AS DATE) fDate,
  33.                                                     CAST(outbound.scheduledTime AS DATE) nDate,
  34.                                                         inbound.idfmg_flightinfos idfmg_flightinfos_inbound,
  35.                                                         outbound.idfmg_flightinfos idfmg_flightinfos_outbound
  36.                                                 FROM
  37.                                                     (((SELECT DISTINCT
  38.                                                         scheduledTime,
  39.                                                         MAX(dataVersion) dataVersion,
  40.                                                             rotationSegment,
  41.                                                             IF(rotationId = 0, flightId, rotationId) rotationId
  42.                                                     FROM
  43.                                                    
  44.         (SELECT inbound.*
  45.         FROM (SELECT idfmg_flightinfos
  46.                 FROM (SELECT c.rotationId, c.rotationSegment, MAX(c.dataVersion) as dataVersion
  47.                         FROM(SELECT rotationId, MAX(rotationSegment) as rotationSegment
  48.                             FROM fmg_flightinfos_idx_a a
  49.                                 LEFT JOIN fmg_flightinfos_cx cx ON a.scheduledTimeDate = cx.scheduledTimeDate AND a.flightId = cx.flightId
  50.                             WHERE a.scheduledTimeDate >= DATE_SUB('2019-12-06', INTERVAL 3 DAY)
  51.                             GROUP BY rotationId) b
  52.                             INNER JOIN fmg_flightinfos_idx_a c ON b.rotationId = c.rotationId AND b.rotationSegment = c.rotationSegment
  53.                         GROUP BY c.rotationId, c.rotationSegment) as base
  54.                         INNER JOIN fmg_flightinfos_idx_a inbound ON base.rotationId = inbound.rotationId AND base.rotationSegment = inbound.rotationSegment AND base.dataVersion = inbound.dataVersion
  55.                 WHERE inbound.scheduledTimeDate >= DATE_SUB('2019-12-06', INTERVAL 3 DAY)) as final
  56.             INNER JOIN fmg_flightinfos inbound ON final.idfmg_flightinfos = inbound.idfmg_flightinfos)fmg_flightinfos
  57.                                          
  58.                                                     WHERE
  59.                                                             serviceType IN ('LL' , 'CP', 'CA', 'LF','CC','LI','LZ')
  60.                                                            
  61.                                                     GROUP BY fmg_flightinfos.rotationSegment , fmg_flightinfos.rotationId) F
  62.                                                     LEFT JOIN (SELECT DISTINCT
  63.                                                     scheduledTime,
  64.                                                         MAX(dataVersion) dataVersion,
  65.                                                             rotationSegment,
  66.                                                             IF(rotationId = 0, flightId, rotationId) rotationId
  67.                                                     FROM
  68.         (SELECT outbound.*
  69.         FROM (SELECT idfmg_flightinfos
  70.                 FROM (SELECT c.rotationId, c.rotationSegment, MAX(c.dataVersion) as dataVersion
  71.                         FROM(SELECT rotationId, MAX(rotationSegment) as rotationSegment
  72.                             FROM fmg_flightinfos_idx_d a
  73.                                 LEFT JOIN fmg_flightinfos_cx cx ON a.scheduledTimeDate = cx.scheduledTimeDate AND a.flightId = cx.flightId
  74.                             WHERE a.scheduledTimeDate >= DATE_SUB('2019-12-06', INTERVAL 3 DAY)
  75.                             GROUP BY rotationId) b
  76.                             INNER JOIN fmg_flightinfos_idx_d c ON b.rotationId = c.rotationId AND b.rotationSegment = c.rotationSegment
  77.                         GROUP BY c.rotationId, c.rotationSegment) as base
  78.                         INNER JOIN fmg_flightinfos_idx_d outbound ON base.rotationId = outbound.rotationId AND base.rotationSegment = outbound.rotationSegment AND base.dataVersion = outbound.dataVersion
  79.                 WHERE outbound.scheduledTimeDate >= DATE_SUB('2019-12-06', INTERVAL 3 DAY)) as final
  80.             INNER JOIN fmg_flightinfos outbound ON final.idfmg_flightinfos = outbound.idfmg_flightinfos)fmg_flightinfos
  81.            
  82.            
  83.                                                     WHERE
  84.                                                             serviceType IN ('LL' , 'CP', 'CA', 'LF','CC','LI','LZ')
  85.                                                     GROUP BY fmg_flightinfos.rotationSegment , fmg_flightinfos.rotationId) N ON (F.rotationSegment < N.rotationSegment)
  86.                                                         AND (F.rotationId = N.rotationId))
  87.                                                     INNER JOIN fmg_flightinfos inbound ON F.dataVersion = inbound.dataVersion
  88.                                                         AND F.rotationSegment = inbound.rotationSegment
  89.                                                         AND F.scheduledTime = inbound.scheduledTime
  90.                                                         AND F.rotationId = inbound.rotationId)
  91.                                                         LEFT JOIN
  92.                                                     fmg_flightinfos outbound ON N.dataVersion = outbound.dataVersion
  93.                                                         AND N.rotationSegment = outbound.rotationSegment
  94.                                                     AND IF(outbound.actualTime > '0000-00-00 00:00:00',outbound.actualTime,IF(outbound.blockTime > '0000-00-00 00:00:00',outbound.blockTime,IF(outbound.internalTime > '0000-00-00 00:00:00',outbound.internalTime,outbound.scheduledTime))) >  
  95.                                                 IF(inbound.actualTime > '0000-00-00 00:00:00',inbound.actualTime,IF(inbound.blockTime > '0000-00-00 00:00:00',inbound.blockTime,IF(inbound.internalTime > '0000-00-00 00:00:00',inbound.internalTime,inbound.scheduledTime)))  
  96.                                                         AND N.rotationId = outbound.rotationId
  97.                                                 WHERE
  98.                                                    ( CAST(inbound.scheduledTime AS DATE) >= '2019-12-06' OR CAST(outbound.scheduledTime AS DATE) >= '2019-12-06')
  99.                                                 ORDER BY STA)x
  100.                                           LEFT JOIN cgs02.airports dep ON x.DEP = dep.iata
  101.                                           LEFT JOIN cgs02.airports arr ON(x.ARR = arr.iata)
  102.                                           LEFT JOIN cgs02.citypairs c ON dep.idairports = c.depidairports AND arr.idairports = c.arridairports
  103.                                           LEFT JOIN (SELECT AirlineDesignator, FlightNumber, ScheduledTimeOfArrival, AircraftRegistration, IDTangoHistory FROM cgs02.tango_history_cgs ORDER BY IDTangoHistory DESC LIMIT 0, 100000) tango
  104.                                                     ON CONCAT(tango.AirlineDesignator, ' ', tango.FlightNumber) = REPLACE(x.fFlight,'  ',' ') AND CAST(tango.ScheduledTimeOfArrival AS DATE) = CAST(x.STA AS DATE) AND tango.AircraftRegistration = x.acRegistration
  105.                                           LEFT JOIN (SELECT AirlineDesignator, FlightNumber, ScheduledTimeOfDeparture, AircraftRegistration, IDTangoHistory FROM cgs02.tango_history_cgs ORDER BY IDTangoHistory DESC LIMIT 0 , 100000) tangoOutbound
  106.                                                     ON CONCAT(tangoOutbound.AirlineDesignator, ' ', tangoOutbound.FlightNumber) = REPLACE(x.nFlight,'  ',' ') AND CAST(tangoOutbound.ScheduledTimeOfDeparture AS DATE) = CAST(x.STD AS DATE) AND tangoOutbound.AircraftRegistration = x.acRegistration
  107.                                          ) BULLSHIT ORDER BY idfmg_flightinfos_inbound,idfmg_flightinfos_outbound
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement