CBSE Class 12 Informatics Practices
Question 68 of 79
Database Query using SQL — Question 26
Back to all questions 26
Question Consider the following table:
Table: ITEM
| Itemno | Iname | Price | Quantity |
|---|---|---|---|
| 101 | Soap | 50 | 100 |
| 102 | Powder | 100 | 50 |
| 103 | Facecream | 150 | 25 |
| 104 | Pen | 50 | 200 |
| 105 | Soapbox | 20 | 100 |
Write queries based on the table ITEM:
(a) Display the information of all the items.
(b) Display item name and price value.
(c) Display soap information.
(d) Display the item information whose name starts with letter 's'.
(e) Display a report with item number, item name and total price (total price = price * quantity).
(f) SELECT DISTINCT PRICE FROM ITEM;
(g) SELECT COUNT(DISTINCT Price) FROM ITEM;
(a)
SELECT * FROM ITEM;+--------+-----------+-------+----------+
| ITEMNO | INAME | PRICE | QUANTITY |
+--------+-----------+-------+----------+
| 101 | SOAP | 50 | 100 |
| 102 | POWDER | 100 | 50 |
| 103 | FACECREAM | 150 | 25 |
| 104 | PEN | 50 | 200 |
| 105 | SOAPBOX | 20 | 100 |
+--------+-----------+-------+----------+
(b)
SELECT INAME, PRICE
FROM ITEM;+-----------+-------+
| INAME | PRICE |
+-----------+-------+
| SOAP | 50 |
| POWDER | 100 |
| FACECREAM | 150 |
| PEN | 50 |
| SOAPBOX | 20 |
+-----------+-------+
(c)
SELECT * FROM ITEM
WHERE INAME = 'SOAP';+--------+-------+-------+----------+
| ITEMNO | INAME | PRICE | QUANTITY |
+--------+-------+-------+----------+
| 101 | SOAP | 50 | 100 |
+--------+-------+-------+----------+
(d)
SELECT * FROM ITEM
WHERE INAME LIKE 'S%';+--------+---------+-------+----------+
| ITEMNO | INAME | PRICE | QUANTITY |
+--------+---------+-------+----------+
| 101 | SOAP | 50 | 100 |
| 105 | SOAPBOX | 20 | 100 |
+--------+---------+-------+----------+
(e)
SELECT ITEMNO, INAME, (PRICE * QUANTITY) AS Total_Price
FROM ITEM;+--------+-----------+-------------+
| ITEMNO | INAME | Total_Price |
+--------+-----------+-------------+
| 101 | SOAP | 5000 |
| 102 | POWDER | 5000 |
| 103 | FACECREAM | 3750 |
| 104 | PEN | 10000 |
| 105 | SOAPBOX | 2000 |
+--------+-----------+-------------+
(f)
+-------+
| PRICE |
+-------+
| 50 |
| 100 |
| 150 |
| 20 |
+-------+
(g)
+-----------------------+
| COUNT(DISTINCT Price) |
+-----------------------+
| 4 |
+-----------------------+