Queries Based on the Aviaco Database from Database Systems (Rob and Coronel)

Total Page:16

File Type:pdf, Size:1020Kb

Queries Based on the Aviaco Database from Database Systems (Rob and Coronel)

Queries based on the AviaCo database from Database Systems (Rob and Coronel)

Paste the SQL for queries below the problem statement.

1. Make a list of the Aircraft registration numbers as well as their model manufacturers and model names.

SELECT `AIRCRAFT`.`AC_NUMBER`, `MODEL`.`MOD_MANUFACTURER`, `MODEL`.`MOD_NAME` FROM `MODEL` LEFT JOIN `ROBOCOR`.`AIRCRAFT` ON `MODEL`.`MOD_CODE` = `AIRCRAFT`.`MOD_CODE`

2. Make a list of customers and the flights and dates flown on. Include customers that have never flown.

SELECT `CUSTOMER`.`CUST_FNAME`, `CUSTOMER`.`CUST_LNAME`, `CHARTER`.`CHAR_TRIP`, `CHARTER`.`CHAR_DATE` FROM `CHARTER` RIGHT JOIN `ROBOCOR`.`CUSTOMER` ON `CHARTER`.`CUST_NUM` = `CUSTOMER`.`CUST_NUM`

SELECT CONCAT(`CUSTOMER`.`CUST_FNAME`,' ', `CUSTOMER`.`CUST_LNAME`) fullname, `CHARTER`.`CHAR_TRIP`, `CHARTER`.`CHAR_DATE` FROM `CHARTER` RIGHT JOIN `ROBOCOR`.`CUSTOMER` ON `CHARTER`.`CUST_NUM` = `CUSTOMER`.`CUST_NUM`

3. Make a list that has both the customer names and the employee names.

SELECT `CUSTOMER`.`CUST_FNAME`, `CUSTOMER`.`CUST_LNAME` FROM `CUSTOMER` UNION SELECT `EMPLOYEE`.`EMP_FNAME`, `EMPLOYEE`.`EMP_LNAME` FROM `EMPLOYEE`

4. Make a list having customers and employees who flew on February 7, 2004.

SELECT `CUSTOMER`.`CUST_FNAME`, `CUSTOMER`.`CUST_LNAME` FROM `CHARTER`, `ROBOCOR`.`CUSTOMER` WHERE `CHARTER`.`CUST_NUM` = `CUSTOMER`.`CUST_NUM` AND `CHARTER`.`CHAR_DATE` ='2/7/2004' UNION SELECT `EMPLOYEE`.`EMP_FNAME`, `EMPLOYEE`.`EMP_LNAME` FROM `CHARTER`,`ROBOCOR`.`CREW`, EMPLOYEE WHERE `CHARTER`.`CHAR_TRIP` = `CREW`.`CHAR_TRIP` AND `CREW`.`EMP_NUM` = `EMPLOYEE`.`EMP_NUM` AND `CHARTER`.`CHAR_DATE` ='2/7/2004'

5. Count the number of charters to the various destinations.

SELECT `CHARTER`.`CHAR_DESTINATION`, COUNT(`CHARTER`.`CHAR_TRIP`) thecount FROM `CHARTER` GROUP BY CHAR_DESTINATION ORDER BY thecount DESC LIMIT 0,5

6. Calculate the fuel efficiency (number of miles per gallon) for all of the flights. Group the information by aircraft used for the trip.

7. Calculate the average fuel efficiency for each of the aircraft. Put them in order from most efficient to least efficient.

8. Customers are charged by the mile (the Charter table lists distances) depending on the model they fly (the Model table lists charge per mile). Make a list of the customers, their flights and the mileage charge. Group by customer. 9. Total up the mileage charge for each customer.

Recommended publications