Q1: Consider a table ‘product’ shown below.
Write a SQL command for the following
statements.
id Name Price quantity category
11 Pepsi 50 2 A
12 Biscuit 70 7 B
13 Cake 90 6 B
14 Chips 40 2 A
15 Toffee 50 8 C
(i) To display name and quantity.
Select name and quantity from product;
(ii) To display the records in ascending order of price.
Select * from product order by price;
(iii) To display the records in descending order of price.
Select * from product order by price desc;
(iv) To display average price.
Select avg(price) from product;
(v) To display total of the price.
Select sum(price) from product;
(vi) To delete the records whose price is less than 50.
Delete from product where price < 50;
(vii) To display lowest price.
Select min(price) from product;
(viii) To display highest price.
Select max(price) from product;
(ix) To display sum of price category wise.
Select category, sum(price) from product group by category;
(x) To change the name “biscuit” to “cherry”.
Update product set name=”cherry” where id=12;