Sql-Worksheet-Class 12
Sql-Worksheet-Class 12
LEFT SIDE
Consider the following tables STORE and ITEM and answer the question:
Table: STORE TABLE:ITEM
SNO SNAME AREA INO INAME PRICE SNO
S01 ABC COMPUTRONICS GKII T01 MOTHER BOARD 12000 S01
S02 ALL INFOTECH MEDIA CP T02 HARD DISK 5000 S01
S03 TECH SHOPPE NEHRU PLACE T03 KEYBOARD 500 S02
S04 GEEKS TECNO SOFT NEHRU PLACE T04 MOUSE 300 S01
S05 HITECH TECH STORE CP T05 MOTHER BOARD 13000 S02
T06 KEYBOARD 400 S03
T07 LCD 6000 S04
T08 LCD 5500 S05
T09 MOUSE 350 S05
T10 HARD DISK 4500 S03
(I) Write queries to create tables STORE and ITEM.
(II) Insert values into the tables.
(III) Display structure.
(IV) Display the contents of the tables.
(V) Write the SQL queries.
(VI) Write the output for the SQL commands.
RIGHT SIDE
AIM:
Aim: To create tables STORE and ITEM in MYSQL database.
(I) Write queries to create tables STORE and ITEM.
CREATE TABLE STORE
(SNO CHAR(3), SNAME VARCHAR(24), AREA VARCHAR(15));
(2) To display Minimum and Maximum Price of each INAME from the table ITEM.
SELECT INAME, MIN(PRICE), MAX(PRICE) FROM ITEM
GROUP BY INAME;
(3) To display INAME, PRICE of all items and their respective SNAME where they
are available.
SELECT B.INAME, B.PRICE, A.SNAME FROM STORE A, ITEM B
WHERE A.SNO=B.SNO;
Table :DEALER
DC DNAME
101 RELIABLE STATIONERS
103 CLASS PLASTICS
102 CLEAR DEALS
RIGHT SIDE
Aim: To create tables STOCK and DEALER in MYSQL database.
(I) Write queries to create tables STOCK and DEALER.
CREATE TABLE STOCK
(INO INT, ITEMNAME VARCHAR(24), ,DC INT, QTY INT,
PRICE DECIMAL(10,2), SDATE DATE);
(2) To display ITEMNO, Item name and DEALER NAME of those items from BOTH
table whose PRICE is more than Rupees 10.
SELECT A.INO, A.ITEMNAME, B.DNAME FROM STOCK A, DEALER B
WHERE A.DC=B.DC AND PRICE>10;
(3) To display the details of those items whose dealer code (DC)is 102 or Quantity in
Stock (QTY) is more than 100 from the table STOCK.
SELECT * FROM STOCK
WHERE DC=102 OR QTY>100;
Table:SALGRADE
SGRADE SALARY HRA
S01 56000 18000
S02 32000 12000
S03 24000 8000
(I) Write queries to create tables EMPLOYEE and SALGRADE.
(II) Insert values into the tables
(III) Display structure
(IV) Display the contents of the tables
(V) Write the SQL queries:
(VI) Write the output for the SQL commands:
RIGHT SIDE
Aim: To create tables EMPLOYEE and SALGRADE in MYSQL database.
(2) To display NAME, DESIG, SALARY, HRA of ALL EMPLOYEEs from BOTH
the tables
SELECT A.NAME, A.DESIG, B.SALARY, B.HRA
FROM EMPLOYEE A, SALGRADE BWHERE A.SGRADE=B.SGRADE;
(3) To display the content of the entireNAME, DOJ from EMPLOYEEs table, whose
DOJ is in between 09-Feb-2006 and 08-Aug-2009.
SELECT NAME, DESIG,DOJ FROM EMPLOYEE
ORDER BY DOJ DESC;
Table : ISSUED
BID QTYISSUED
T001 4
C001 5
F001 2
(I) Write queries to create tables BOOKS and ISSUED.
(II) Insert values into the tables
(III) Display structure
(IV) Display the contents of the tables
(V) Write the SQL queries:
(VI) Write the output of the SQL commands:
RIGHT SIDE
Aim: To create tables BOOKS and ISSUED in MYSQL database.
(I) Write queries to create tables BOOKS and ISSUED.
CREATE TABLE BOOKS
(BIDCHAR(4), BNAME VARCHAR(24), AUTHORNAME VARCHAR(24),
PUBLISHERS VARCHAR(24), PRICE DECIMAL(10,2), TYPE VARCHAR(12),
QTY INT);
(3) To display the BOOKID, BOOKNAME and QTYISSUED for all books that has
been issued.
SELECT A.BID, A.BNAME, B.QTYISSUED FROM BOOKS A, ISSUED B
WHERE A.BID=B.BID;
BNAME PRICEAFTERUPDATION
FASTCOOK 405.00
THE TEARS 700.00
MY FIRST C++ 400.00
C++BRAINWORKS 400.00
THUNDERBOLTS 800.00
(3) BID BNAME QTYISSUED
C001 FASTCOOK 5
F001 THE TEARS 2
T001 MY FIRST C++ 4
(4) BNAME AUTHORNAME
FASTCOOK LATA KAPOOR
MY FIRST C++ BRAIN AND BROOKE
(5) COUNT(DISTINCT PUBLISHERS)
3
EXERCISE NO:5
LEFT SIDE
Consider the following DEPT and WORKER tablesand answer the question:
Table : DEPT
DCODE DEPARTMENT CITY
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI
Table : WORKER
WNO NAME DOJ DOB GENDER DCODE
1001 George K 2013-09-02 1991-09-01 M D01
1002 RymaSen 2012-12-11 1990-12-15 F D03
1003 Mohitesh 2013-02-03 1987-09-04 M D05
1007 Anil Jha 2014-01-17 1984-10-19 M D04
1004 Manila Sahai 2012-12-09 1986-11-14 F D01
1005 R SAHAY 2013-11-18 1987-03-31 M D02
1006 Jaya Priya 2014-06-09 1985-06-23 F D05
(I) Write queries to create tables DEPT and WORKER.
(II) Insert values into the tables.
(III) Display structure.
(IV) Display the contents of the tables.
(V) Write the SQL queries.
(VI) Write the output for the SQL commands.
RIGHT SIDE
Aim: To create tables DEPT and WORKER in MYSQL database.
(I) Write queries to create tables DEPT and WORKER.
CREATE TABLE DEPT
(DCODECHAR(3), DEPARTMENT VARCHAR(24), CITY VARCHAR(15));
(2) To display the Name of all the FEMALE workers, their department and city from
BOTH the tables.
SELECT B.NAME, A.DEPARTMENT, A.CITY
FROM DEPT A, WORKER B WHERE A.DCODE=B.DCODE;
(3) To display the WNO, Name and age of the workers from the table WORKER
SELECT WNO, NAME, (YEAR(CURDATE( ))-YEAR(DOB)) AS AGE FROM
WORKER;