DBMS Lab Assignment 3
DBMS Lab Assignment 3
1. Write a query that selects all customers whose ratings are equal to or greater than
ANY of Serres.
2. Write a query using ANY or ALL that will find all salespeople who have no
customers located in their city.
Query -> SELECT CNAME, CITY, 'HIGH RATING' RATING FROM CUSTOMERS WHERE
RATING>200 UNION SELECT CNAME, CITY, 'LOW RATING' RATING FROM CUSTOMERS
WHERE RATING <= 200;
6. Write a command that produces the name and number of each salesperson and
each customer with more than one current order. Put the results in alphabetical
order.
Query -> SELECT SNAME, SNUM, CNAME FROM SALESPEOPLE JOIN CUSTOMERS
USING(SNUM) WHERE SNUM IN ( SELECT SNUM FROM CUSTOMERS GROUP BY SNUM
HAVING COUNT(SNUM)>1) ORDER BY SNAME,CNAME;
7. Form a union of three queries. Have the first select the snums of all salespeople in
San Jose; the second, the cnums of all customers in San Jose; and the third the
onums of all orders on October 3. Retain duplicates between the last two queries
but eliminate any redundancies between either of them and the first.
Query -> SELECT SNUM FROM SALESPEOPLE WHERE CITY = 'San_Jose' UNION
-> SELECT DISTINCT SNUM FROM ORDERS WHERE SNUM IN (
-> SELECT SNUM FROM ORDERS WHERE ODATE = '1990-10-03');
8. Write a command that removes all orders from customer Clemens from the
Orders table.
Query -> DELETE FROM ORDERS WHERE CNUM IN ( SELECT CNUM FROM CUSTOMERS
WHERE CNAME = ‘Clemens’);
9. Write a command that increases the rating of all customers in Rome by 100.
Query -> UPDATE CUSTOMERS SET RATING = RATING + 100 WHERE CITY = ‘Rome’;
SELECT * FROM CUSTOMERS;