Jump to content

please guys help me to get this query


Roman10

Recommended Posts

Hi guys
 
I have 3 tables which are (flight, model, airplane)
Flight: fid, pid, aid, plannedDeparture, actualDeparture, passengerCount, destination
Model: mid, name, usefulLoad, pilotCount 
Airplane: aid, mid, oid, hid, dateAqu
 
and I need to generate a report (query) for overloaded flights. Assuming the following:
 - the passenger/pilot weight is 160 lb on average;
 - fuel takes 65% of the useful load.

Including in the report the following data: flightID (fid), destination, plannedDeparture, passengerCount, airplaneID (aid), airplaneModel (Model.name), usefulLoad, totalLoad (calculated), overLoad (calculated), passengerSurplus (calculated).
 
 
and I'm really sticking on it, I'm not an advanced user on mysql so I would really appreciate helping me here.
 
** I attached my schema ..

p3-GolfClub-DB.txt

Link to comment
Share on other sites

Have I got this right?

 

Take the Piper Archer TX with a usefulLoad of 870

Fuel is 65% which leaves (870 * 0.35) for passengers and pilot ie 304.5

Take out the pilot and that leaves an allowance of (304.5 - 160) 144.5 for passengers.

 

This is less than the 160 average so cannot carry passengers, or, at least, is overloaded with a single passenger ???

Link to comment
Share on other sites

try

SELECT f.fid
, f.destination
, f.plannedDeparture
, f.passengerCount
, f.aid
, m.name
, m.usefulLoad
,  m.usefulLoad*0.65 + (m.pilotcount + f.passengercount)*160 as totalLoad
, CASE 
    WHEN m.usefulLoad*0.65 + (m.pilotcount + f.passengercount)*160 > usefulLoad 
        THEN m.usefulLoad*0.65 + (m.pilotcount + f.passengercount)*160 - usefulLoad
    ELSE 0
    END as overLoad
, CASE 
    WHEN m.usefulLoad*0.65 + (m.pilotcount + f.passengercount)*160 > usefulLoad 
        THEN CEIL((m.usefulLoad*0.65 + (m.pilotcount + f.passengercount)*160 - usefulLoad)/160)
    ELSE 0
    END as passengerSurplus
FROM flight f
INNER JOIN airplane a USING (aid)
INNER JOIN model m USING (mid)
ORDER BY plannedDeparture

post-3105-0-83520100-1386144954_thumb.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.