Sunteți pe pagina 1din 43

id)0)00selectQ1 .

Consider the following tables STOCK and DEALERS and write the
queries for (i) to (iv) and output for (v):
Table : STOCK
Itcode Itname Dcode Qty unitpr Stkdate
444 Drawing Copy 101 110 21 31-July-2010
445 Sharpener Camlin 102 235 3 01-Aug-2010
450 Eraser Natraj 101 40 2 17-Aug-2010
452 Gel Pen Montex 103 50 5 30-Dec-2009
457 Geometry Box 101 35 45 15-Nov-2009
467 Parker Premium 102 60 205 27-Oct-2009
469 Office File 103 32 25 13-Sep-2010
Creat(itcode
Table : DEALERS
Dcode Dname
101 Vikash Stationers
102 Bharat Drawing Emporium
103 Banaras Books Corporation
(i) To display details of all items in the stock table in descending order of Stkdate.

(ii)To increase unitpr (unit price) by 20% in the stock table for the items which has been
purchased before 2010.
Select itname

(iii) To display the details of those items whoseDcode (Dealer Code) is 102 or Qty (Quantity) is
more than 50 from the table stock.
(iv) To display minimum unit price of items for each dealer individually as per Dealer
Code from the table stock.

(v) SELECT COUNT(DISTINCT Dcode)FROM STOCK;

Q2. Create the following tables Product and Client.Write SQL commands .
Table : Product
P_ID ProductName Manufacturer Price
TP01 Talcom Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120

FW12 Face Wash XYZ 95


(a) To display the details of those clients whose city is not Delhi.

(b) To display the Client name, City From table Client and Product Name and Price from table
Product, with their corresponding matching P_ID.

(c) To display the details of those client whose City is Banglore..

(d) To display the details of Products whose Price is in the range of 50 to 100 (Both value
included).
88
(e) To increase the Price of all Product by 25%.

Q3.Create the following tables Doctor and Salary and execute the SQL Commands
Table :DOCTOR
ID NAME DEPT SEX EXPERIENCE
101 John ENT M 12
104 Smith ORRHPEDIC M 5
107 George CARDIOLOGY M 10
114 Lara SKIN F 3
109 K George MEDICINE F 9
105 Johnson ORRHPEDIC M 10
117 Lucy ENT F 3
111 Bill MEDICINE F 12
130 Morphy ORRHPEDIC M 15

Table :SALARY
ID BASIC ALLOWANCE CONSULTATION
101 12000 1000 300
104 23000 2300 500
107 32000 4000 500
114 12000 5200 100
109 42000 1700 200
105 18900 1690 300
130 21700 2600 300
(a). Display NAME of all doctors who are in “MEDICINE” having more than 10

years experience and basic more than 10000.


(b). Display the average salary of all doctors working in “ENT” department using
DOCTOR table where as salary=basic + allowance

(c). Display the minimum ALLOWANCE of female doctors.

(d). Display the highest consultation fee among all male doctors.

(e). Display the total number of doctors in ORRHPEDIC department.

Q4. Consider the following tables and answer the following:


(
EMPLOYEE
W_ID FIRSTNAME LASTNAME CITY
102 SAM TONES PARIS
105 SARAH ACKERMAN NEW YORK
144 MANILA SENGUPTA NEW DELHI
210 GEORGE SMITH HOWARD

DESIGN
W_ID SALARY BENEFITS DESIGNATION
102 75000 15000 MANAGER
300 45000 10000 CLERK
335 40000 10000 CLERK
400 32000 7500 SALESMAN
451 28000 7500 SALESMAN
i).Display FirstName and City of Employee of PARIS

ii).Display W_ID, salary and designation of all SALESMAN.

iii).Se
iv).Increase the benefits of employee having W_ID = 102 b

v).
vi).Count number of employees city wise.

vii).
viii).Select COUNT(DISTINCT designation) from design;

Q5.Consider the tables ITEMS&COMPANY. Write SQL commands for the statements (i) to (iv) and
give the outputs for SQL queries (v)
Table : ITEMS
ID PNAME PRICE MDATE QTY
T001 Soap 12.00 11/03/2007 200
T002 Paste 39.50 23/12/2006 55
T003 Deodorant 125.00 12/06/2007 46
T004 Hair Oil 28.75 25/09/2007 325
T005 Cold Cream 66.00 09/10/2007 144
T006 Tooth Brush 25.00 17/02/2006 455

Table : COMPANY
ID COMP City
T001 HLL Mumbai
T006 Colgate Delhi
T009 HLL Mumbai
T007 Paras Haryana
T005 Ponds Noida
T0011 Wipro Ahmedabad
i) Display the items detail produced by Wipro &Paras.;;

ii)
ii) To display product name, company name & price for those items, which IDs are equal to the

IDs of company.

iii) To delete the items produced before 2007.

iv) To display the total stock value of items.


v) SELECT comp, city FROM company order by city;

Q6.Consider the following table CLUB and MEMBER. Write the SQL commands for the statements (i)
to (iv) and output (v).
Table: CLUB
GCode GameName Number Fees StrtingDate
101 Carom Board 2 5000 23-Jan-2004
102 Badminton 2 12000 12-Dec-2003
103 Table Tennis 4 8000 14-Feb-2004
105 Chess 2 9000 01-Jan-2004
108 Lawn Tennis 4 25000 19-Mar-2004
Table: MEMBER
Code Name GCode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jasvinder 101
4 Robert 103
(i) To display the name of all the games with their GCodes.
(ii) To display all information of those games which are having fees more than 10000.
(iii) To display the information of CLUB table in descending order of StartDate.
(iv) To display Name and Number of All the members from the Table CLUB and MEMBER.
(v) SELECT COUNT(DISTINCT Number) FROM CLUB;

Q7. Write SQL Commands for (i) to (iv) and write the outputs for (v) on the basis of table :

Table : FURNITURE
NO ITEM NAME TYPE DATEOFSTOCK PRICE DISCOUNT
1 White Lotus Double Bed 2002-02-23 3000 25
2 Pink feathers Baby Cot 2002-01-29 7000 20
3 Dolphin Baby Cot 2002-02-19 9500 20
4 Decent Office Table 2002-02-01 25000 30
5 Comfort zone Double Bed 2002-02-12 25000 30
6 Donald Baby cot 2002-02-24 6500 15
7 Royal Finish Office Table 2002-02-20 18000 30
8 Royal tiger Sofa 2002-02-22 31000 30
9 Econo sitting Sofa 2001-12-13 9500 25
10 EatinParadise Dinning 2002-12-19 11500 25
Table
i. To show all the information about the Baby cots from the furniture table.
ii. To list the itemname which are priced at more than 15000 from the furniture table.
iii. To list itemname and type of those items, in which dateofstock is before 2002-02-01 from
the furniture table in descending order of itemname.
iv. To display itemname and dateofstock of those items, in which the discount percentage is
more than 25 from the furniture table.
v. To count the number of items, whose TYPE is “Sofa” from the furniture table.

Q8. Write the SQL commands for the i) to iv) and write the output of the (vi) on the basis of table
TEACHER. Table:TEACHER
No. Name Age Department Dateofapp Salary Sex
1 Jugal 34 Computer 10/01/97 12000 M
2 Sharmila 31 History 24/03/98 20000 F
3 Sandeep 32 Maths 12/12/96 30000 M
4 Sangeeta 35 History 01/07/99 40000 F
5 Rakesh 42 Maths 05/09/97 25000 M
6 Shyam 50 History 27/06/98 30000 M i) To show all
7 Shivam 44 Computer 25/02/97 21000 M information about the
8 Shalakha 33 Maths 31/07/97 20000 F teacher of History
department.
ii) To list the names of female teachers who are in Maths department

.
iii) To list names of all teachers with their date of appointment in ascending order.

iv) To insert a new row in the TEACHER table with the following data:
9,’Raja’, 26,’Computer’, “13/05/95”, 23000,’M’
v) Write create statement to create above table by taking proper data types.
vi) Give the output of the following SQL statements.

a. Select COUNT(distinct department) from TEACHER;


b. Select MAX(Age) from TEACHER where SEX=’F’;

c. Select AVG(Salary) from TEACHER where SEX=’M’;

d. Select SUM(Salary) from TEACHER where DATOFJOIN<”1996-07-12”;


Q9.Consider the following tables EMPLOYEE and SALARIES. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii)

TABLE: EMPLOYEE

EMPID EMPNAME SECTION SEX EXPERIENCE


101 Sabeena PRODUCTION F 10
102 Siva ACCOUNTS M 15
103 Ayaz INSPECTION M 10
104 Gayathri PRODUCTION F 8

TABLE: SALARIES

EMPID SALARY INCENTIVE ALLOWANCE


101 18000 1800 1325
103 23150 3100 1121
105 13120 2300 1240
106 12550 1250 1005

i. Display EMPNAME of all staff who are in “ACCOUNTS” having more than 10 years experience
from the table EMPLOYEE.
ii. Display the average PAY of all staff working in “INSPECTION” department using the tables
EMPLOYEE and SALARIES.
iii. Display the minimum INCENTIVE of female staff.
iv. Display the highest ALLOWANCE among all male staff.
v. SELECT count (*) from EMPLOYEE where SEX = “F”.
vi. SELECT EMPNAME, SECTION, ALLOWANCE from EMPLOYEE, SALARIES where SECTION =
“ACCOUNTS” and EMPLOYEE.EMPID = SALARIES.EMPID;
vii. SELECT EMPNAME from EMPLOYEE where SECTION= INSPECTION and SEX=’M’;
viii. Select count (distinct SECTION) from EMPLOYEE;

Q10. Read the instructions given below and answer accordingly: (MySql)
Note: Write MySql commands for (i) to (x) based on the following table.
SUPPLIERS
SCODE SNAME CITY STATE AMOUNT
1001 RAJESH BHIKHIWIND PUNJAB 5000
1002 RAJAT AMRITSAR PUNJAB 5400
1003 PUNEET SONIPAT HARYANA 6200
1004 RACHNA FARIDABAD HARYANA 8400
1005 RAMAN JAMUNANAGAR HARYANA 8940
1006 PRAGTI BISHRAMPUR CHATTISGARH 4800
1007 PRAHALAD BABRALA UTTER PARDESH 3000
1008 KOCHER LAKHERI RAJASTHAN 2500

i) Show sname of suppliers whose name is starting with letter ‘P’


ii) Show sname, city of suppliers who belongs to ‘PUNJAB’
iii) Show sname of suppliers in descending order.
iv) Show sname, city of suppliers who belongs to either ‘HARYANA’ or ‘PUNJAB’
v) Change the amount to 5000 where scode is 1008.
vi) Delete the suppliers from SUPPLIERS table who belongs to state ‘UTTAR PARDESH’.
vii) Insert a new record in SUPPLIERS table with following description:
1009, ‘NEETA ARORA’,’DELHI’, ‘DELHI’,7500
viii) Add a new column (COMMISSION DECIMAL(7,2)) in the above table.
ix) Display total no. of records in table.
x) Display no. of employees in each city.

Q11.Consider the table Flight given below, write command in SQL for (1) to (4) and output for (5)
to (8).
Table :FLIGHT
Flight_No Origin Destination Seats FlightDate Rate
1005 Varanasi Nepal 275 12-Dec-07 3000
2785 Delhi Kerala 290 17-Jan-08 5500
6587 Mumbai Varanasi 435 19-Feb-08 5000
1265 Varanasi Nepal 200 02-Jan-08 5400
4457 Delhi Lucknow 150 22-Feb-08 4500
6856 Varanasi Mumbai 180 03-Mar-08 6000

(1) To display Flight flying between Varanasi and Nepal.


(2) To display the different Origin of Flights.
(3) To display list of flights in descending order of Rate.
(4) To display flight details of the flight whose flightdate is after Jan 2008.
(5) SELECT Flight_No, Destination FROM Flight WHERE Destination LIKE ‘_u%’;
(6) SELECT Origin, COUNT(*) FROM Flight GROUP BY Origin;
(7) SELECT Origin, Destination FROM Flight WHERE seats>400;
(8) SELECT SUM(Rate),MAX( Seats) FROM Flight;

Q12. Consider the following table named “GYM” with details about fitness items being sold in the
store.Write command of SQL for (i) to (iv) and output for (v) to (vii)
Table :GYM
ICODE INAME PRICE BRANDNAME
G101 Power Fit Exerciser 20000 Power Gymea
G102 Aquafit Hand Grip 1800 Reliable
G103 Cycle Bike 14000 Ecobike
G104 Protoner Extreme 30000 Coscore
Gym
G105 Message Belt 5000 MessagExpert
G106 Cross Trainer 13000 GTCFitness

(i) To display the names of all the items whose name starts with “A”.
(ii) To display ICODEs and INAMEs of all items,whoseBrandname is Reliable or Coscore.
(iii)To change the Brandname to “Fit trend India” of the item. Whose ICODE as “G101”.
(iv) Add a new row for a new item in GYM with the details: “G107”,”Vibro
exerciser’,21000,”GTCFitness”
(v) SELECT COUNT(DISTINCT(BRANDNAME)) FROM GYM;
(vi) SELECT MAX(PRICE) FROM GYM;
(vii) SELECT INAME FROM GYM WHERE INAME LIKE “%T”;

Q13.
Q14.
Q15.
+

Q
1
6
.

Q
1
7
.
Q18.

Commented [S1]:
Where
Q19.

Q20.
Q21. Write SQL commands for (i) to (IV) and write output for (v) on the basis of
PRODUCTS relation given below:

PCODE PNAME COMPANY PRICE STOCK DATE OF WARRANTY


MANUFACTURE
P001 TV BPL 10000 200 12-01-2008 3
P002 TV SONY 12000 150 23-03-2007 4
P003 PC LENOVO 39000 100 09-04-2008 2
P004 PC COMPAQ 38000 120 20-06-2009 2
P005 HANDYCAM SONY 15000 250 23-03-2007 3

i) To show details of all the PC with stock more than 110.


ii) To list the company which gives warranty for more than 2 years.
iii) To find stock value of the BPL Company where stock value is sum of the products ofprice and
stock.
iv) To count the number of PRODUCTS which shall be out of warranty on 20-NOV-2011.
v) Select MAX(price)from PRODUCT where WARRANTY<=3
Q22.
Q23
Q24
Q 25
Q26.
Q27.
Q28.
Q29.
Q30.
select

S-ar putea să vă placă și