Dbms Lab Assignment 3.docx

  • Uploaded by: Shiv Shankar Mistry
  • 0
  • 0
  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Dbms Lab Assignment 3.docx as PDF for free.

More details

  • Words: 443
  • Pages: 5
DBMS LAB ASSIGNMENT-3 1. Write a query that selects all customers whose ratings are equal to or greater than ANY of Serres.

Query -> SELECT * FROM CUSTOMERS WHERE RATING >= ANY ( -> SELECT RATING FROM CUSTOMERS WHERE SNUM IN ( -> SELECT SNUM FROM SALESPEOPLE WHERE SNAME = 'SERRES'));

2. Write a query using ANY or ALL that will find all salespeople who have no customers located in their city.

Query -> SELECT SNUM FROM SALESPEOPLE WHERE ( -> SNUM, CITY) NOT IN ( -> SELECT SNUM, CITY FROM CUSTOMERS);

3. Write a query that selects all orders for amounts greater than any for the customers in London.

Query -> SELECT * FROM ORDERS WHERE AMT > ANY ( -> SELECT AMT FROM ORDERS WHERE CNUM IN ( -> SELECT CNUM FROM CUSTOMERS WHERE CITY = 'LONDON'));

4. Write the above query using MIN or MAX. Query -> SELECT * FROM ORDERS WHERE AMT > ( -> SELECT MIN(AMT) FROM CUSTOMERS NATURAL JOIN ORDERS WHERE CITY = 'LONDON');

5. Create a union of two queries that shows the names, cities, and ratings of all customers. Those with rating of 200 or greater will also have the words “High Rating”, while the others will have the words “Low Rating”.

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;

Related Documents

Dbms Lab Assignment 3.docx
October 2019 31
Dbms Assignment No. 1
June 2020 4
Dbms Assignment No 2
June 2020 4
New Dbms Lab Manual
November 2019 9
Dbms Lab Manual
April 2020 2

More Documents from "aditya"