In: Computer Science
Question 1: Car Dealership Scenario. Complete parts A – D based on the database specifications listed below.
Database Specification
Parts A - D
Queries: Write and run SQL queries for the following questions. Use the minimum number of tables required for each query.
SQL queries :
i) We have to make a relational table for the cars sold to the
customers by the salesperson. Hence the table will contain
attributes from the tables Customer, Salesperson & Cars. The
query will be :
SELECT FIRST_NAME, LAST_NAME FROM PURCHASE WHERE AGE>40
AND MAKE='FORD'
ii) We have created a PURCHASE table as described in the solution above and hence we can use this table and the Salesperson table. The query will be :
SELECT FIRST_NAME, LAST_NAME FROM SALESPERSON WHERE EMPLOYEE_ID NOT IN (SELECT EMPLOYEE_ID FROM PURCHASE WHERE MAKE='FORD')
iii) We can build a table OWNS to store data for which dealer bought which car and now owns it. We can then use this table to answer this query as it will contain data from both DEALERS and CARS table:
SELECT SUM(SUGGESTED_PRICE) FROM OWNS WHERE DEALERSHIP_NAME='Sils Car Deals'
iv) The PURCHASE table will have all the information of cars purchased by any customer and also cars sold by the salespersons and also the price at which deal is made between the two. Hence we can use this to solve this query:
SELECT AVG(ACTUAL_PRICE) FROM PURCHASE WHERE YEAR='2008' AND MAKE='HONDA' AND MODEL='CIVIC'