0% found this document useful (0 votes)
28 views

SQL Practicals

The document contains 10 sections that provide SQL queries and outputs. Sections 1-9 each provide SQL queries for (i)-(iv) and the output for (v). Section 10 similarly provides SQL queries for (i)-(iv) and output, but uses a table called Product instead of Transact. The queries perform operations like selecting, filtering, ordering, grouping and aggregating data from the tables.

Uploaded by

H2411 Kishore V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

SQL Practicals

The document contains 10 sections that provide SQL queries and outputs. Sections 1-9 each provide SQL queries for (i)-(iv) and the output for (v). Section 10 similarly provides SQL queries for (i)-(iv) and output, but uses a table called Product instead of Transact. The queries perform operations like selecting, filtering, ordering, grouping and aggregating data from the tables.

Uploaded by

H2411 Kishore V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

6.

Consider the table SHOPPE and ACCESSORIES, write the query for (i) to (iv) and output
for (v)

i)To display Name and Price of all the Accessories in descending order of their Price.

SELECT NAME,PRICE FROM ACCESSORIES ORDER BY PRICE


DESC;
(ii) To display Id and Sname of all the Shoppe location in „Nehru Place‟

SELECT ID,SNAME FROM SHOPPE WHERE AREA='NEHRU PLACE';

(iii) To display Name, Minimum and Maximum Price of each Name from ACCESSORIES
table.

SELECT NAME,MIN(PRICE),MAX(PRICE) FROM ACCESSORIES


GROUP BY NAME;
(iv) To display Name, Price of all Accessories and their respective SName from table
SHOPPE and ACCESSORIES where Price is 5000 or more.

SELECT NAME,PRICE,SNAME FROM SHOPPE S,


ACCESSORIES A WHERE S.ID=A.ID AND PRICE>=5000;
(v) SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE>5000;
NAME

Mother Board
LCD

1
7. Consider the table items, write the query for (i) to (iv) and output for (v).

(i) To display all INAME from ITEMS table in descending order of their
PRICE.
Select INAME from items order by price desc;

(ii) To display all ITEMS details whose price is in range of 15000 and
25000.
Select * from items where price between 15000 and 25000;

(iii) To display Sum of price and TCode where Qty is more than 50
TCode wise (for each TCode)
Select sum(price), tcode from items where qty >50 group by tcode;

(iv) To delete all ITEMS from table where CODE is 1003.


Delete from items where code=1003;

(v) Select Max(Price), Avg(Price) from ITEMS;


Max(price) avg(price)
38000 15940

8. Consider the table employee, write the query for (i) to (iv) and output for (v):

(i) To display all the information of employee whose name begins with M
in ascending order of their DOB.
Select * from employee where name like ‘m%’ order by DOB;

(ii) To display name and DOJ of female employees working in DCODE


D01 or D02
2
Select name,DOJ from employee where gender =’female’ and dcode in
(‘D01’,’D02’);

(iii) To Display number of employee gender wise.


Select count(*) from employee group by gender;

(iv) To Display unique DCODE from table Employee.


Select distinct dcode from employee;

(v)
Select Max(DOB), Min(DOB) from EMPLOYEE;
Max(DOB) Min(DOB)
1991-09-01 1984-10-19
9. Consider the table Transact, write the query for (i) to (iv) and output for (v):

TABLE: TRANSACT
TRNO ANO AMOUNT TYPE DOT
T001 101 2500 Withdraw 2017-12-21
T002 103 3000 Deposit 2015-06-01
T003 102 2000 Withdraw 2017-05-12
T004 103 1000 Deposit 2017-10-22
T005 102 12000 Deposit 2016-11-06

(i) To display details of all transactions of TYPE Withdraw from TRANSACT table.
Select * from TRANSACT where TYPE=’Withdraw’;

(ii) To display ANO and AMOUNT of all Deposit and Withdrawals done in month of
“May” 2017 from table TRANSACT.
Select ANO, AMOUNT from TRANSACT where DOT like ‘%-05-%’;

(iii) To display first date of transaction (DOT) from table TRANSACT for Account having
ANO as 102.
Select MIN(DOT) from TRANSACT where ANO=102;
(iv) To display ANO, AMOUNT, TYPE of those transactions done in the year
2017;
Select ano,amount,type from transact where DOT like ‘2017%’;

(v) SELECT DISTINCT ANO, TYPE FROM TRANSACT;


ANO TYPE
101 Withdraw
103 Deposit
102 Withdraw
10. Consider the table Transact, write the query for (i) to (iv) and output for (v):
Table : Product
PCode PName Price Color Manufacture
S001 Mobile Phones 30000 Silver Samsung
S002 Refrigerator 20000 Cherry LG
S003 TV 45000 Black Samsung
S004 Washing Machine 12000 White LG
S005 Air Conditioner 50000 White voltas

(i) To display PCode, PName of all the product, who manufacture “Samsung”.
Select Pcode, Pname from product where manufacture=” Samsung”;

(ii) To display PName, PCode and price of all the products whose price >=23000.
Select Pname, Pcode, Price from Product where price>=23000;

3
(iii)To display number of product manufacture wise.
Select count (*) from Product group by Manufacture;

(iv) To display information of all the Products whose product color


is ‘White’, ‘Silver’.
Select * from Product where color in (‘White’, ‘Silver’);

(v) Select min(price), count ( Distinct Color) from Product;


min(price) count ( Distinct Color)
12000 4

You might also like