CSC415 :DBMS

SQL Assignment:





Consider the following relational schema for a used car database (primary keys are italicized):

Note: Create your own instantiations for testing using the appropriate SQL.

CARS (cid, mid, cyear)
BUYERS (bid, bname, bcity, age)
MANUFACTURERS (maname, location)
MODELS (mid, maname, model)
SALESPEOPLE (sid, sname, years_employed)
TRANSACTIONS (bid, cid, sid, amount, month, day, year)

Express the following queries using SQL.  The SQL queries should not return duplicates.

1.  Print the bname and bcity of all buyers who have purchased a Ford Mustang for an amount less than $10,000. (Note: Ford is the manufacturer, Mustang is the model.)
2.  Print the sid of all salespeople who have sold both a Ford and a Toyota in 1997.
3.  Print the sid of all salespeople who have sold at least one car of every manufacturer.
4.  Print the sname(s) of all sales people who did not sell any cars in 1997.
5. Print the sname and total sales amount of the salesperson who had the highest total sales (in          dollars) for 1997.
6.  Print the sname, and average amount per transaction (i.e., average sales amount) for every salesperson who has been working less than 10 years, and who has sold at least 50 cars. Print the result in descending order of the average sales amount.
Given the following Schema, answer the following querries:

   employee(fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  
   department(dname, dnumber, mgrssn, mgrstartdate)
   dept_locations(dnumber, dlocation)  
   project(pname, pnumber, plocation, dnum)
   works_on(essn, pno, hours)  
   dependent(essn, dependent_name, sex, bdate, relationship) 


         7. Retrieve the name and address of all employees who work for the 
             'Research' department.
         8. For every project located in 'Stafford', list the project number, the
             controlling department number, and the department manager's last name,
             address, and birthdate.
         9. Find the names of employees who work on all the projects controlled
             by department number 5.
        10. Make a list of project numbers for projects that involve an employee
              whose last name is 'Smith', either as a worker or as a manager of the
              department that controls the project.
        11. List the names of all employees with two or more dependents.
        12. Retrieve the names of employees who have no dependents.
        13. List the names of managers who have at least one dependent.