Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Name :-> Amit Awasthi Roll no :->21MCF1R04

Table create :

CREATE TABLE SALEPERSON(

SALESPERSONNUMBER NUMBER(10),

SALESPERSONNAME VARCHAR(20),

CommPercentage NUMBER(10),

YearHire VARCHAR(20),

OfficeNumber VARCHAR(20)

);

INSERT INTO SALEPERSON VALUES(137,'AMIT',10,'1995','34');

INSERT INTO SALEPERSON VALUES(186,'RAHUL',15,'2000','56');

INSERT INTO SALEPERSON VALUES(204,'AJAY',10,'1998','66');

INSERT INTO SALEPERSON VALUES(361,'VIJAY',20,'2002','1227');

SELECT * FROM SALEPERSON;

CREATE TABLE CUSTOMERTABLE(

CUSTOMERNUMBBER NUMBER(10),

CUSTOMERNAME VARCHAR(20),

SALESPERSONNUMBER NUMBER(10),

HQCITY VARCHAR(20)

);

SELECT * FROM CUSTOMERTABLE;

INSERT INTO CUSTOMERTABLE VALUES(0121,'MAIN ST.',137,'NEW YORK');

INSERT INTO CUSTOMERTABLE VALUES(0839,'JANE STORE',186,'CHICAGO');

INSERT INTO CUSTOMERTABLE VALUES(0933,'ABC HOME',137,'LOS ANGELES');

INSERT INTO CUSTOMERTABLE VALUES(1047,'HAEWRSE',137,'LOS ANGELES');

INSERT INTO CUSTOMERTABLE VALUES(1525,'FRED TOOL STORES',361,'ATLANTA');

INSERT INTO CUSTOMERTABLE VALUES(1700,'XYZ STORES',361,'WASHINGTON');

INSERT INTO CUSTOMERTABLE VALUES(1826,'CITY HARDWARE',137,'NEW YORK');

INSERT INTO CUSTOMERTABLE VALUES(2198,'WEESTERN HARDWARE',204,'NEW YORK');


SELECT * FROM CUSTOMERTABLE ;

CREATE TABLE CUSTOMEREMPLOYEE(

CUSTOMERNUMBBER NUMBER(10),

EMPLOYEENUMBER NUMBER(20),

EMPLOYEENAME VARCHAR(10),

TITLE VARCHAR(20)

);

INSERT INTO CUSTOMEREMPLOYEE VALUES(0121,27498,'SMITH','CO-OWNER');

INSERT INTO CUSTOMEREMPLOYEE VALUES(0121,30441,'GARCIA','CO-OWNER');

INSERT INTO CUSTOMEREMPLOYEE VALUES(0933,25270,'CHEN','VP SALES');

INSERT INTO CUSTOMEREMPLOYEE VALUES(0933,30441,'LEVY','SALES MANAGER');

INSERT INTO CUSTOMEREMPLOYEE VALUES(0933,48285,'MORTON','PRESIDENT');

INSERT INTO CUSTOMEREMPLOYEE VALUES(1525,33779,'BAKER','SALESMANAGER');

INSERT INTO CUSTOMEREMPLOYEE VALUES(2198,27470,'SMITH','PRESIDENT');

INSERT INTO CUSTOMEREMPLOYEE VALUES(2198,30441,'JONES','VP SALES');

SELECT * FROM customeremployee;

CREATE TABLE PRODUCTLAB3(

PRODUCTNUMBER NUMBER(10),

PRODUCTNAME VARCHAR(20),

UNITPRICE FLOAT(10)

);

INSERT INTO PRODUCTLAB3 VALUES(16386,'WRENCH',12.95);

INSERT INTO PRODUCTLAB3 VALUES(19440,'HAMMER',17.50);

INSERT INTO PRODUCTLAB3 VALUES(21765,'DRILL',32.99);

INSERT INTO PRODUCTLAB3 VALUES(24013,'SAW',26.25);

INSERT INTO PRODUCTLAB3 VALUES(26722,'PILERS',11.50);

CREATE TABLE SALES(

SALESPERSON NUMBER(10),

PRODUCTNUMBER NUMBER(20),
QUANTITY NUMBER(10)

);

INSERT INTO SALES VALUES(137,19440,473);

INSERT INTO SALES VALUES(137,24013,170);

INSERT INTO SALES VALUES(137,26722,688);

INSERT INTO SALES VALUES(186,16386,1745);

INSERT INTO SALES VALUES(186,19440,2529);

INSERT INTO SALES VALUES(204,21765,809);

INSERT INTO SALES VALUES(204,26722,734);

CREATE TABLE OFFICE(

OFFICENUMBER NUMBER(10),

TELEPHONE VARCHAR(20),

SIZEE NUMBER(10)

);

INSERT INTO OFFICE VALUES(1253,'901-555-4276',120);

INSERT INTO OFFICE VALUES(1227,'901-555-0364',100);

INSERT INTO OFFICE VALUES(1284,'901-555-7334',120);

INSERT INTO OFFICE VALUES(1209,'901-555-3108',95);

Q1. Find the commission percentage and year of hire of salesperson number 186.
query: SELECT COMMPERCENTAGE , YEARHIRE FROM SALEPERSON;

output :

Q2. List the salesperson numbers and salesperson names of those salespersons who have a

commission percentage of 10?


QUERY : ->SELECT SALESPERSONNUMBER , SALESPERSONNAME FROM SALEPERSON where
commpercentage=10;

Output

Q3. List the salesperson number and salesperson name of all of the salespersons.

Query : select salespersonname,salespersonnumber from saleperson ;

Output :

Q. 4. List the salesperson numbers, salesperson names, and commission percentages of the

salespersons whose commission percentage is less than 12.

query: select salespersonname,salespersonnumber,commpercentage from saleperson ;

output :

Q. 5. List the customer numbers and headquarters cities of the customers that have a customer

number of at least 1700.

Query :->SELECT CUSTOMERNUMBBER,HQCITY FROM CUSTOMERTABLE WHERE


CUSTOMERNUMBBER >=1700;
OUTPUT :

Q 6. List the customer numbers, customer names, and headquarters cities of the customers

that are headquartered in New York and that have a customer number higher than 1500.

Query : -> select customernumbber, customername,hqcity from customertable where hqcity =


'NEW YORK' AND customernumbber>=1500;

Result :

7. ‘List the customer numbers, customer names, and headquarters cities of the customers

that are headquartered in New York or that have a customer number higher than 1500.

Query :-> select customernumbber, customername,hqcity from customertable where hqcity = 'NEW
YORK' or customernumbber>=1500;

Result :->

8. List the customer numbers, customer names, and headquarters cities of the customers

that are headquartered in New York or that satisfy the two conditions of having a
customer number higher than 1500 and being headquartered in Atlanta.

Answer :-> select customernumbber, customername,hqcity from customertable where hqcity = 'NEW
YORK' or (customernumbber>=1500 and hqcity = 'ATLANTA');

RESULT :->

Q9. Which cities serve as headquarters cities for General Hardware customers? 10. Find the customer
numbers, customer names, and headquarters cities of those customers with customer numbers greater
than 1000. List the results in alphabetic order by headquarters cities.

Answer :-> SELECT HQCITY FROM CUSTOMERTABLE;

Result :->

10. Find the customer numbers, customer names, and headquarters cities of those customers

with customer numbers greater than 1000. List the results in alphabetic order by

headquarters cities.

Query :-> SELECT CUSTOMERNUMBBER,CUSTOMERNAME,HQCITY FROM CUSTOMERTABLE WHERE


CUSTOMERNUMBBER > 1000 ORDER BY HQCITY ASC;
Result :->

11. Find the average number of units of the different products that Salesperson 137 sold

(i.e., the average of the quantity values in the first three records of the SALES table).

Answer :-> SELECT AVG(QUANTITY)FROM SALES WHERE SALESPERSON=137;

Result :->

Q 12:-> What is the largest number of units of Product Number 21765 that any individual

salesperson has sold?

Query :-> SELECT MAX(QUANTITY)FROM SALES WHERE PRODUCTNUMBER = 21765 ;

Answer:->

Q 13-> How many salespersons have sold Product Number 21765?

QUERY :-> SELECT COUNT(SALESPERSON) FROM SALES WHERE PRODUCTNUMBER = 21765;

Result :->

Q.14 :-> 14. Find the total number of units of all products sold by each salesperson.
Query :-> SELECT salesperson, SUM(QUANTITY) FROM SALES GROUP BY salesperson;

Output :->

Q 15. Find the total number of units of all products sold by each salesperson whose

salesperson number is at least 150.

Query :-> SELECT salesperson, SUM(QUANTITY) FROM SALES WHERE salesperson >150 GROUP BY
SALESPERSON ;

OUTPUT :->

Q 16. Find the total number of units of all products sold by each salesperson whose

salesperson number is at least 150.

Query :-> SELECT salesperson, SUM(QUANTITY) FROM SALES WHERE salesperson >150 GROUP BY
SALESPERSON ;

OUTPUT :->

Q17. Find the total number of units of all products sold by each salesperson whose

salesperson number is at least 150. Include only salespersons whose total number of

units sold is at least 5000.

Anwer :-> SELECT salesperson, SUM(QUANTITY) FROM SALES WHERE salesperson >150 GROUP
BY SALESPERSON HAVING SUM(QUANTITY)>4000;
Result :->

Q 18 Find the name of the salesperson responsible for Customer Number 1525.?

Query :-> select * from SALEPERSON, CUSTOMERTABLE where


SALEPERSON.SALESPERSONNUMBER=CUSTOMERTABLE.SALESPERSONNUMBER and
CUSTOMERNUMBBER=1525;

OUTPUT :->

Q.19. List the names of the products of which salesperson Adams has sold more than 2000

Units?

Query : -> SELECT PRODUCTNAME FROM SALEPERSON ,PRODUCTLAB3,SALES WHERE


SALES.PRODUCTNUMBER = PRODUCTLAB3.PRODUCTNUMBER AND SALEPERSON.SALESPERSONNAME =
'ADAMS' AND SALES.QUANTITY >2000;

Result :

Q 20. Which salespersons with salesperson numbers greater than 200 have the lowest

commission percentage?’’ (We’ll identify salespersons by their salesperson number.)

QUERY :-> SELECT SALESPERSONNAME FROM SALEPERSON WHERE SALESPERSONNUMBER > 200 AND
COMMPERCENTAGE =(SELECT MIN(COMMPERCENTAGE) FROM SALEPERSON WHERE
SALESPERSONNUMBER > 200);
RESULT :->

QUESTION 2 :->

Q1. Find the book number, book name, and number of pages of all the books published by London
Publishing Ltd. List the results in order by book name.

QUERY :-> SELECT BOOKNUMBER,BOOKNAME,PAGES FROM BOOK WHERE PUBLISHERNAME = 'London


Publishing Ltd.';

RESULT :->

Q2. How many books of at least 400 pages does Good Reading Bookstores carry that were published
by publishers based in Paris, France?

QUERY :-> SELECT * FROM BOOK , PUBLISHER WHERE BOOK.PAGES > 400 AND BOOK.PUBLISHERNAME
= PUBLISHER.PUBLISHERNAME AND COUNTRY = 'France' OR COUNTRY = 'PARIS' ;

RESULT :

Q3: List the publishers in Belgium, Brazil, and Singapore that publish books written by authors who
were born before 1920.
QUERY :-> SELECT * FROM AUTHOR , PUBLISHER WHERE AUTHOR.DOB <1920 AND
AUTHOR.AUTHORNAME = PUBLISHER.PUBLISHERNAME;

RESULT : ->

Q 4. . How many books did each publisher in India, Norway; Nairobi, Kenya; and Auckland, New
Zealand, publish in 2001?

QUERY : -> SELECT COUNT(PUBLISHERNAME) FROM PUBLISHER WHERE YEAROFFOUNDATION = 2001


WHERE PUBLISHER.COUNTRY = 'INDIA' OR PUBLISHER.CITY = 'NORWAY' OR PUBLISHER.CITY = 'PARIS' OR
PUBLISHER.CITY = 'BRAZIL';

RESULT :->

Q 5. Which publisher published the book that has the earliest publication year among all the books
that Good Reading Bookstores carries?

Query :-> SELECT PUBLISHERNAME FROM BOOK

WHERE PUBLISHEDYEAR=(SELECT MIN(PUBLISHEDYEAR) FROM BOOK;

RESULT :->

You might also like