Informatics Practices
Write SQL commands for (a) to (e) on the basis of PRODUCTS relation given below:
Table: PRODUCTS
PCODE | PNAME | COMPANY | PRICE | STOCK | MANUFACTURE | WARRANTY |
---|---|---|---|---|---|---|
P001 | TV | BPL | 10000 | 200 | 2018-01-12 | 3 |
P002 | TV | SONY | 12000 | 150 | 2017-03-23 | 4 |
P003 | PC | LENOVO | 39000 | 100 | 2018-04-09 | 2 |
P004 | PC | COMPAQ | 38000 | 120 | 2019-06-20 | 2 |
P005 | HANDYCAM | SONY | 18000 | 250 | 2017-03-23 | 3 |
(a) To show details of all Products with stock more than 110.
(b) To list the company which gives warranty of more than 2 years.
(c) To find stock value of the BPL company where stock value is sum of the price and stock of the products.
(d) To show products from products table.
(e) To display the details of those products whose Name either ends with 'Y' or 'O'.
Relational Database
4 Likes
Answer
(a)
SELECT *
FROM PRODUCTS
WHERE STOCK > 110;
Output
+-------+----------+---------+----------+-------+-------------+----------+
| PCODE | PNAME | COMPANY | PRICE | STOCK | MANUFACTURE | WARRANTY |
+-------+----------+---------+----------+-------+-------------+----------+
| P001 | TV | BPL | 10000.00 | 200 | 2018-01-12 | 3 |
| P002 | TV | SONY | 12000.00 | 150 | 2017-03-23 | 4 |
| P004 | PC | COMPAQ | 38000.00 | 120 | 2019-06-20 | 2 |
| P005 | HANDYCAM | SONY | 18000.00 | 250 | 2017-03-23 | 3 |
+-------+----------+---------+----------+-------+-------------+----------+
(b)
SELECT DISTINCT COMPANY
FROM PRODUCTS
WHERE WARRANTY > 2;
Output
+---------+
| COMPANY |
+---------+
| BPL |
| SONY |
+---------+
(c)
SELECT COMPANY, (PRICE + STOCK) AS STOCK_VALUE
FROM PRODUCTS WHERE COMPANY = 'BPL';
Output
+---------+-------------+
| COMPANY | STOCK_VALUE |
+---------+-------------+
| BPL | 10200 |
+---------+-------------+
(d)
SELECT * FROM PRODUCTS;
Output
+-------+----------+---------+-------+-------+-------------+----------+
| PCODE | PNAME | COMPANY | PRICE | STOCK | MANUFACTURE | WARRANTY |
+-------+----------+---------+-------+-------+-------------+----------+
| P001 | TV | BPL | 10000 | 200 | 2018-01-12 | 3 |
| P002 | TV | SONY | 12000 | 150 | 2017-03-23 | 4 |
| P003 | PC | LENOVO | 39000 | 100 | 2018-04-09 | 2 |
| P004 | PC | COMPAQ | 38000 | 120 | 2019-06-20 | 2 |
| P005 | HANDYCAM | SONY | 18000 | 250 | 2017-03-23 | 3 |
+-------+----------+---------+-------+-------+-------------+----------+
(e)
SELECT * FROM PRODUCTS
WHERE PNAME LIKE '%Y' OR PNAME LIKE '%O';
Answered By
3 Likes
Related Questions
Define foreign key.
Match the following clauses with their respective functions.
Column 1 Column 2 ALTER Insert the values in a table UPDATE Restrictions on columns DELETE Table definition INSERT INTO Change the name of a column CONSTRAINTS Update existing information in a table DESCRIBE Delete an existing row from a table CREATE Create a database What are DDL and DML?
Differentiate between primary key and candidate key in a relation.