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 PCs 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 the sum of the products of price and stock.
(d) To show products from PRODUCTS table.
(e) To show the product name of the products which are within warranty as on date.
SQL Queries
3 Likes
Answer
(a)
SELECT *
FROM PRODUCTS
WHERE PNAME = 'PC' AND STOCK > 110;
Output
+-------+-------+---------+-------+-------+-------------+----------+
| PCODE | PNAME | COMPANY | PRICE | STOCK | MANUFACTURE | WARRANTY |
+-------+-------+---------+-------+-------+-------------+----------+
| P004 | PC | COMPAQ | 38000 | 120 | 2019-06-20 | 2 |
+-------+-------+---------+-------+-------+-------------+----------+
(b)
SELECT DISTINCT COMPANY
FROM PRODUCTS
WHERE WARRANTY > 2;
Output
+---------+
| COMPANY |
+---------+
| BPL |
| SONY |
+---------+
(c)
SELECT COMPANY, SUM(PRICE * STOCK) AS StockValue
FROM PRODUCTS
WHERE COMPANY = 'BPL';
Output
+---------+------------+
| COMPANY | StockValue |
+---------+------------+
| BPL | 2000000 |
+---------+------------+
(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 PNAME
FROM PRODUCTS
WHERE DATE_ADD(MANUFACTURE, INTERVAL WARRANTY YEAR) >= CURDATE();
There is no output produced because the warranty of all products has expired.
Answered By
2 Likes
Related Questions
An organization ABC maintains a database EMP-DEPENDENT to record the following details about its employees and their dependents.
EMPLOYEE(AadhaarNo, Name, Address, Department, EmpID) DEPENDENT(EmpID, DependentName, Relationship)Use the EMP-DEPENDENT database to answer the following SQL queries:
(i) Find the names of the employees with their dependents' names.
(ii) Find employee details working in a department, say, 'PRODUCTION'.
(iii) Find employee names having no dependents.
(iv) Find the names of employees working in a department, say, 'SALES' and having exactly two dependents.
Write SQL commands for (i) to (v) on the basis of relation given below:
Table: BOOKS
book_id Book_name author_name Publishers Price Type qty k0001 Let us C Y. Kanetkar EPB 450 Comp 15 p0001 Genuine J. Mukhi FIRST PUBL. 755 Fiction 24 m0001 Mastering C++ K.R. Venugopal EPB 165 Comp 60 n0002 VC++ advance P. Purohit TDH 250 Comp 45 k0002 Programming with Python Sanjeev FIRST PUBL. 350 Fiction 30 (i) To show the books of FIRST PUBL. written by J. Mukhi.
(ii) To display cost of all the books published for FIRST PUBL.
(iii) Depreciate the price of all books of EPB publishers by 5%.
(iv) To display the Book_Name and price of the books more than 3 copies of which have been issued.
(v) To show the details of the book with quantity more than 30.
What are DDL and DML?
Differentiate between primary key and candidate key in a relation.