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

Table: Product

PCode PName Company Price DOM Type


MG329 Marie Gold Cadbury 220 2022-11-25 B
DM222 Dairy Milk Cadbury 170 2023-06-09 T
NB007 Nibbles Dukes 55 2023-07-18 B
GD024 Good Day Britannia 35 2022-12-03 B
HS049 Hide & Seek NULL NULL NULL NULL
LY233 Lays Pepsico 45 2022-10-12 C
MB550 Milky Bar Nestle 20 2022-11-08 T
CK001 Cookies NULL NULL NULL NULL
OR442 Oreo Cadbury 30 2023-07-22 B
LH711 Little Hearts NULL NULL NULL NULL
EC240 Eclairs Candyman 135 2023-04-15 T
MM320 Moms Magic Sunfeast 25 2022-08-27 B
BN016 Bingo NULL 10 NULL C
NC712 Nutri Choice Britannia 65 2023-02-17 B
WF595 Waffy Dukes 50 2023-01-29 T

1. Write a query to display PName, Price, PCode and Type from table Product.
SELECT PName, Price, PCode, Type
FROM Product;

2. Write a query to display different Companies (without repeat) from table Product.
SELECT DISTINCT ( Company )
FROM Product;

3. Write a query to display all the Products whose Price is more than 50.
SELECT *
FROM Product
WHERE Price > 50;

4. Write a query to display all the Products whose company is not Britannia.
SELECT *
FROM Product
WHERE Company != ‘Britannia’;

5. Write a query to display PName, Company and Price of all the products of Cadbury
company whose price is less than 100.
SELECT PName, Company, Price
FROM Product
WHERE Company = ‘Cadbury’ AND Price < 100 ;

6. Write a query to display all the Products whose type is either T or B.


SELECT *
FROM Product
WHERE Type = ‘T’ OR Type = ‘B’;

7. Write a query to display PName and Price of all the Products whose price is between
60 and 100.
SELECT PName, Price
FROM Product
WHERE Price BETWEEN 60 AND 100;
1
8. Write a query to display all the Products of Company Dukes, Britannia, Sunfeast,
Candyman and Perfetti.
SELECT *
FROM Product
WHERE Company IN (‘Dukes’, ‘Britannia’, ‘Sunfeast’, ‘Candyman’,
‘Perfetti’);

9. Write a query to display all the Products having Price other than 40,45,50,55,60,65.
SELECT *
FROM Product
WHERE Price NOT IN (40, 45, 50, 55, 60, 65);

10. Write a query to display PName, Company and Price of all the Products whose
PName starts with alphabet M.
SELECT PName, Company, Price
FROM Product
WHERE PName LIKE “M%”;

11. Write a query to display all the Products not having alphabet ‘a’ as second character
in their PName.
SELECT PName
FROM Product
WHERE PName NOT LIKE “_a%” ;

12. Write a query to display all the Products having NULL value in Company column.
SELECT *
FROM Product
WHERE Company IS NULL;

13. Write a query to display all the records in the alphabetical order of PName.
SELECT *
FROM Product
ORDER BY PName ASC;

14. Write a query to display PName, Company and Price of Britannia and Cadbury
company in the order of their Price from highest to lowest.
SELECT PName, Company, Price
FROM Product
WHERE Company = ‘Britannia’ OR Company = ‘Cadbury’
ORDER BY Price DESC;

15. Write a query to display PName and New Price of Products. The New Price is
calculated as Price + 10% of Price.
SELECT PName, Price + Price*10/100 AS “New Price”
FROM Product;

16. Write a query to display average Price of all the Products.


SELECT AVG(Price)
FROM Product;

17. Write a query to display Minimum Price from the products of type ‘B’.
SELECT MIN(Price)
FROM Product
WHERE Type = ‘B’;

2
Grouping Result: (GROUP BY clause)

18. Write a query to display number of Products for each Company.


SELECT Company, COUNT(Company)
FROM Product
GROUP BY Company;

19. Write a query to display Sum of Price of the Products of each Type.
SELECT Type, SUM(Price)
FROM Product
GROUP BY Type;

Placing Conditions on Groups (HAVING clause)

20. Write a query to display average Price of products of Cadbury company.


SELECT Company, AVG(Price)
FROM Product
GROUP BY Company
HAVING Company = ‘Cadbury;

21. Write a query to display all the Companies where the number of Products are less
than 3.
SELECT Company, COUNT(*)
FROM Product
GROUP BY Company
HAVING COUNT(*) < 3;

3
JOIN QUERIES
Table: DEPT (Parent Table)

Table: EMP (Child Table)

1. Write a query to display all the records from table Dept and Emp.

SELECT *
FROM Dept, Emp
WHERE Dept.DeptId = Emp.DeptId;

2. Write a query to display DeptId, DName, EName and Desig from Table Dept and
Emp.

SELECT Dept.DeptId, DName, EName, Desig


FROM Emp, Dept
WHERE Emp.DeptId = Dept.DeptId;

3. Write a query to display PName, DName, Location and Salary of those Employees
whose Salary is more than 40000.

SELECT PName, DName, Location, Salary


FROM Emp, Dept
WHERE Emp.DeptId = Dept.DeptId AND Salary > 40000;

4. Write a query to display EId, DeptId, EName and DName of all the Managers.

SELECT EId, E.DeptId, EName, DName


FROM Product E, Dept D
WHERE E.DeptId = D.DeptId AND Desig = “Manager” ;

----- X -----

You might also like