Informatics Practices
Consider the following tables STORE and SUPPLIERS. Write SQL commands for the statements (i) to (iii) and give the output for SQL query (iv).
Table: STORE
ItemNo | Item | Scode | Qty | Rate | LastBuy |
---|---|---|---|---|---|
2005 | Sharpener Classic | 23 | 60 | 8 | 2009-06-31 |
2003 | Ball Pen 0.25 | 22 | 50 | 25 | 2010-02-01 |
2002 | Gel Pen Premium | 21 | 150 | 12 | 2010-02-24 |
2006 | Gel Pen Classic | 21 | 250 | 20 | 2009-03-11 |
2001 | Eraser Small | 22 | 220 | 6 | 2009-01-19 |
2004 | Eraser Big | 22 | 110 | 8 | 2009-12-02 |
2009 | Ball Pen 0.5 | 21 | 180 | 18 | 2009-11-03 |
Table: SUPPLIERS
Scode | Sname |
---|---|
21 | Premium Stationery |
23 | Soft Plastics |
22 | Tetra Supply |
(i) To display details of all the items in the Store table.
(ii) To display ItemNo and item name of those items from store table whose rate is more than 15.
(iii) To display the details of those items whose supplier code is 22 or Quantity in store is more than 110 from the table Store.
(iv) SELECT Rate*Qty FROM STORE WHERE Itemno = 2004;
SQL Queries
2 Likes
Answer
(i)
SELECT * FROM STORE;
Output
+--------+-------------------+-------+-----+------+------------+
| ItemNo | Item | Scode | Qty | Rate | LastBuy |
+--------+-------------------+-------+-----+------+------------+
| 2001 | Eraser Small | 22 | 220 | 6 | 2009-01-19 |
| 2002 | Gel Pen Premium | 21 | 150 | 12 | 2010-02-24 |
| 2003 | Ball Pen 0.25 | 22 | 50 | 25 | 2010-02-01 |
| 2004 | Eraser Big | 22 | 110 | 8 | 2009-12-02 |
| 2005 | Sharpener Classic | 23 | 60 | 8 | 2009-06-30 |
| 2006 | Gel Pen Classic | 21 | 250 | 20 | 2009-03-11 |
| 2009 | Ball Pen 0.5 | 21 | 180 | 18 | 2009-11-03 |
+--------+-------------------+-------+-----+------+------------+
(ii)
SELECT ItemNo, Item FROM STORE WHERE Rate > 15;
Output
+--------+-----------------+
| ItemNo | Item |
+--------+-----------------+
| 2003 | Ball Pen 0.25 |
| 2006 | Gel Pen Classic |
| 2009 | Ball Pen 0.5 |
+--------+-----------------+
(iii)
SELECT * FROM STORE WHERE Scode = 22 OR Qty > 110;
Output
+--------+-----------------+-------+-----+------+------------+
| ItemNo | Item | Scode | Qty | Rate | LastBuy |
+--------+-----------------+-------+-----+------+------------+
| 2001 | Eraser Small | 22 | 220 | 6 | 2009-01-19 |
| 2002 | Gel Pen Premium | 21 | 150 | 12 | 2010-02-24 |
| 2003 | Ball Pen 0.25 | 22 | 50 | 25 | 2010-02-01 |
| 2004 | Eraser Big | 22 | 110 | 8 | 2009-12-02 |
| 2006 | Gel Pen Classic | 21 | 250 | 20 | 2009-03-11 |
| 2009 | Ball Pen 0.5 | 21 | 180 | 18 | 2009-11-03 |
+--------+-----------------+-------+-----+------+------------+
(iv) SELECT Rate*Qty FROM STORE WHERE Itemno = 2004;
Output
+------------+
| Rate * Qty |
+------------+
| 880 |
+------------+
Answered By
1 Like
Related Questions
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 Differentiate between the following statements:
(i) ALTER and UPDATE
(ii) DELETE and DROP
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.