Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
33 views

11, "Aftab", 24, "Surgery". (25/02/98), 300, "M"

Ssqqll
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

11, "Aftab", 24, "Surgery". (25/02/98), 300, "M"

Ssqqll
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Q-5 (B)

1 Write SQL commands for (i) to (vii) and write the outputs for (vii) on the 1998
basis of table HOSPITAL.
No Name Age Department Dateofadmit Charges Sex
1 Arpit 62 Cardiology 21/01/98 300 M
2 Zafrina 22 ENT 12/12/97 250 F
3 Kareem 32 Dentistry 19/02/98 200 M
4 Arun 12 Cardiology 11/01/98 300 M
5 Zubin 30 ENT 12/01/98 250 M
6 Ketika 16 ENT 24/02/98 250 F
7 Ankita 29 Surgery 20/02/98 800 F
8 Zareen 45 Cardiology 22/02/98 300 F
9 Kush 19 Surgery 12/01/98 800 M
10 Shilpa 23 Skin 21/02/98 400 F

(i) To select all the information of patients of cardiology department.


(ii) To list the names of female patients who are in ENT department.
(iii) To list names of all patients with their date of admission in ascending
order.
(iv) To display patient's name, charges, age for only female patients.
(v) To count the number of patient with Age < 30.
(vi) To insert a new row in the HOSPITAL table with the following data:
11, "Aftab", 24, "Surgery". {25/02/98}, 300, "M"

(vii) Give the output of following SQL statements:


 SELECT COUNT(DISTINCT charges) FROM hospital
 SELECT MIN(age) FROM hospital WHERE sex = "F"
 SELECT SUM(charges) FROM hospital WHERE department =
"ENT":
 SELECT AVG(charges) FROM hospital WHERE
dateofadm<{12/02/98}
2 Write SQL commands for (i) to (vii) and write the output for (vii) on the 1999
basis of teacher relation given below:
Teacher
No Name Age Department DateofJoin Salary Sex
1 Jugal 24 Computer 10/01/97 12000 M
2 Sharmila 21 History 24/03/98 20000 F
3 Sandeep 22 Maths 12/12/96 30000 M
4 Sageeta 25 History 01/07/99 40000 F
5 Rakesh 22 Maths 05/09/97 25000 M
6 Shyam 30 History 27/06/97 30000 M
7 Shiv Om 34 Computer 25/02/97 21000 M
8 Shalakha 23 Maths 31/07/97 20000 F
(i) To show all information about the teacher of History department.
(ii) To list the name of female teachers who are in Hindi department.
(iii) To list the names of all the teachers with their date of joining in
ascending order.
(iv) To display Teachers Name, Salary, Age for male teachers only.
(v) To count the number of teachers with age > 23.
(vi) To insert a new row in the Teacher table with the following data.
9, “Raja”, 26, “Computer”, {13/05/95}, 2300, "M"
(vii) Give the output of the following SQL statements :
 SELECT COUNT (DISTINCT department) FROM teacher;
 SELECT MAX(age) FROM teacher WHERE sex = "F";
 SELECT AVG(salary) FROM teacher WHERE sex = "M";
 SELECT SUM(salary) FROM teacher WHERE
dateofjoin<{12,07/96};
3 Write SOL commands for (i) to (iv) and write the outputs for (v) on the basis 2000
of table CLUB.
Table : Club
CoachID CoachName Age Sports Dateofapp Pay Sex
1 Kukreja 35 Karate 27/03/1996 1000 M
2 Ravina 34 Karate 20/01/1998 1200 F
3 Karan 34 Squash 19/02/1998 2000 M
4 Tarun 33 Basketball 01/01/1998 1500 M
5 Zubin 36 Swimming 12/01/1998 750 M
6 Ketaki 36 Swimming 24/02/1998 800 F
7 Ankita 39 Squash 20/02/1998 2200 F
8 Zareen 37 Karate 22/02/1998 1100 F
9 Kush 41 Swimming 13/01/1998 900 M
10 Shailya 37 Basketball 19/02/1998 1700 M
(i) To show all information about the swimming coaches in the club.
select * from club where Sport = "Swimming";
(ii) To list name of all coaches with their date of appointment
(DATEOFAPP) in descending order.
select Name from club order by Dateofapp;
(iii) To display a report, showing coachname, pay, age and bonus (15% of
pay) for all the coaches.
(iv) To insert a new row in the CLUB table with the following data :
11, "PRAKASH", 37, "SQUASH", {25/02/98}, 2500, "M"

(v) Give the output of following SQL statements :


 SELECT COUNT (DISTINCT sports) FROM club;
 SELECT MIN (age) FROM club WHERE sex = "F";
 (iii)SELECT AVG(pay) FROM club WHERE sports ="KARATE";
 SELECT SUM(pay) FROM club WHERE dateofapp > {31/01/98};
(vi) Assume that there is one more table COACHES in the database as
shown below:
Table: Coaches
SportsPerson Sex Coach_No
Ajay M 1
Seema F 2
Vinod M 1
Taneja F 3

What will be the output of the following query :


SELECT sportsperson, coachname FROM club, coaches WHERE coach id =
coach_no;
04 Write SQL commands for (i) to (vii) on the basis of the table STUDENT.
Student Class Name Game GGrade Supw SGrade
No
10 7 Sameer Cricket B Photography A
11 8 Sujit Tennis A Gardening C
13 7 Kamal Swimming B Photography B
14 9 Archana Basket Ball A Literature A
15 10 Arpit Cricket A Gardening C
(i) Display the names of the students who are getting grade 'C' in either
Game or SupW.
(ii) Display the number of students getting grade 'A' in Cricket.
(iii) Display the different games offered in the school.
(iv) Display the SUPW taken up by the students, whose name starts with
“A”.
(v) Add a new column named 'Marks'.
(vi) Assign a value 200 for Marks for all those who are getting Grade 'B' or
above in Game.
(vii) Arrange the whole table in the alphabetical order of SUPW.
5 Given the following Lab relations : 2002
No ItemName Cost Quantity Dateof Warranty Oprational
PerItem Purchase
1 Computer 60000 9 21/05/96 2 7
2 Printer 15000 3 21/05/97 4 2
3 Scanner 13900 1 29/08/98 3 1
4 Camera 21901 2 13/06/96 1 2
5 Hub 8000 1 31/10/99 2 1
6 UPS 5000 5 21/05/96 1 4
7 Plotter 25000 2 11/01/2000 2 2
Write SQL command for questions (i) to (vi).
(i) To select the Itemname purchased after 31/10/97.
(ii) To list the ItemName, which are within the Warranty period till present
date.
(iii) To list the ItemName in ascending order of the date of purchase where
quantity is more than 3.
(iv) To display ItemName, CostPerltem and Quantity whose Warranty is
over.
(v) To count the number of items whose cost is more than 10000.
(vi) To insert a new record in the Lab table with the following data :
I 8. "VCR", 10000. 2. 2 2 2000 . 1, 2

(vii) Give the output of the following SQL command :


 SELECT MIN (DISTINCT quantity) FROM lab;
 SELECT MIN(warranty) FROM lab WHERE quantity = 2;
 SELECT SUM(costperitem) FROM lab WHERE quantity >2;
SELECT AVG(csostperitem) FROM lab WHERE dateofpurchase<{l/199};

06. (b) Given the following tables for a database LIBRARY.


2004

Write SQL command for questions (i) to (vi)


(i) To show Book name, Author name and Price of books of EPB publishers
(ii) To list the names of books of Fiction Type
(iii) To display the names and price of the books in descending order of their price
(iv) To increase the price of all books of First Publ. by 50
(v) To display the Book_Id, Book_Name and Quantity_Issued for all books which have been
issued. (The query will require contents from both the tables)
(vi) To insert a new row in the table Issued having the following data :
“F0002”, 4

(vii) Give the output of the following queries based on the above tables :
 SELECT COUNT(DISTINCT Publishers) FROM Books
 SELECT SUM(Price) FROM Books WHERE Quantity >5
 SELECT Book_Name, Author_Name FROM Books WHERE Price<500
 SELECT COUNT (*) FROM Books
07. (b) Consider the following tables EMPLOYEES and EMPSALARY. Write SQL
commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
2005

(i) To display Firstname, Lastname, Address and City of all employees living in
Paris from the table EMPLOYEES.
(ii) To display the content of EMPLOYEES table in descending order of
FIRSTNAME.
(iii) To display the Firstname, Lastname, and Total Salary of all Managers from
the tables EMPLOYEES and EMPSALARY, where Total Salary is calculated as
Salary + Benefits.
(iv) To display the Maximum salary among Managers and Clerks from the table
EMPSALARY.

(v) SELECT FIRSTNAME, SALARY FROM EMPLOYEES, EMPSALARY WHERE


DESIGNATION = ‘Salesman’ AND EMPLOYEES.EMPID = EMPSALARY.EMPID;
(vi) SELECT COUNT (DISTINCT DESIGNATION)FROM EMPSALARY;
(vii) SELECT DESIGNATION, SUM(SALARY) FROM EMPSALARY GROUP BY
DESIGNATION HAVING COUNT (*)>2;
(viii) SELECT SUM (BENEFITS) FROM EMPLOYEES WHERE DESIGNATION =
’Clerk’;

08. (b) Consider the following tables. Write SQL commands for the statements (i) to (iv) and
give outputs for SQL queries (v) to (viii) 2007

(i) To display the names of all Senders from Mumbai.


(ii) To display the RecID), SenderName, SenderAddress, RecName, RecAddress
for every Recipient.
(iii) To display Recipient details in ascending order of RecName.
(iv) To display number of Recipients from each city.

(v) SELECT DISTINCT SenderCity FROM Sender;


(vi) SELECT A. SenderName, B.RecName FROM Sender A, Recipient B WHERE A.
SenderlD = B.SenderlD AND B.RecCity = ‘Mumbai’;
(vii) SELECT RecName, RecAddress FROM Recipient WHERE RecCity NOT IN
(‘Mumbai’, ‘Kolkata’);
(viii) SELECT RecID, RecName FROM Recipient WHERE SenderID=’MU02'
ORSenderID=’ND50';

09.(b) Consider the following tables GARMENT and FABRIC. Write SQL commands for
the statements (i) to (iv) and give outputs for (v) to (viii). 2009

(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of


GCODE

(ii) To display the details of all the GARMENTs, which have READYDATE in
between 08-DEC-07 and 16-JUN-08 (inclusive of both the dates).

(iii) To display the average PRICE of all the GARMENTs, which are made up of
FABRIC with FCODE as F03.

(iv) To display FABRICwise highest and lowest price of GARMENTs from GARMENT
table. (Display FCODE of each GARMENT along with highest and lowest price).

(v) SELECT SUM(PRICE) FROM GARMENT WHERE FCODE=‟F01‟;

(vi) SELECT DESCRIPTION, TYPE FROM GARMENT, FABRIC WHERE


GARMENT.FCODE =FABRIC.FCODE AND GARMENT.PRICE > = 1260;

(vii) SELECT MAX(FCODE) FROM FABRIC;

(viii) SELECT COUNT (DISTINCT PRICE) FROM GARMENT;


10.(b) Consider the following tables. Write SQL commands for the statements (i) to (iv) and
give outputs for SQL queries (v) to (viii). 2010

Write SQL commands for the following statements :

(i) To display details of all the items in the Store table in ascending order of
LastBuy.
(ii) To display ItemNo and Item name of those items from Store table Whose Rate
is more than 15 Rupees.
(iii)To display the details of those items whose Suppliers code (Scode) is 22 or
Quantity in Store (Qty) is more than 110 from the table Store.
(iv) To display Minimum Rate of items for each Supplier individually as per
Scode from the table Store.
Give the output of the following SQL queries:
(i) SELECT COUNT (DISTINCT Scode) FROM Store;
(ii) SELECT Rate*Qty FROM Store WHERE ItemNO = 2004;
(iii)SELECT Item, Sname FROM Store S, Suppliers P WHERE S.Scode = P.Scode AND
Item No = 2006 ;
(iv) SELECT MAX (LastBuy) FROM Store ;
11.(b)Consider the following tables WORKER and PAYLEVEL and answer the given
questions. 2011
Write SQL commands for the following statements:
(i) To display the details of all WORKERs, descending order of DOB.
(ii) To display NAME and DESIG of those WORKERs whose PLEVEL is
either P001 or P002.
(iii)To display the content of all the WORKERs table, whose DOB is in
between „19-JAN-1984‟ and 18-JAN-1987‟.
(iv) To add a new row with the following :
19, „Days Kishore‟, „Operator‟, „P003‟. „19-Jun-2008‟, „11-Jul-1984‟

Give the output of the following SQL queries :


(i) SELECT COUNT (PLEVEL), PLEVEL FROM WORKER GROUP
BY PLEVEL;
(ii) SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
(iii) SELECT Name, Pay FROM WORKER W, PAYLEVEL P WHERE
W.PLEVEL = S.PLEVEL AND P.ECODE<13;
(iv) SELECT PLEVEL, PAY+ALLOWANCE FROM PAYLEVEL
WHERE PLEVEL = „P003‟;
12.(b) Consider the following tables CARDEN and CUSTOMER and answer the questions.
2012
13. (b) Consider the following tables GAMES and PLAYER. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
S.P. 1
(i) To display the name of all Games with their Gcodes
(ii) To display details of those games which are having PrizeMoney more than 7000.
(iii) To display the content of the GAMES table in ascending order of ScheduleDate.
(iv) To display sum of PrizeMoney for each of the Number of participation groupings (as
shown in column Number 2 or 4)

(v) SELECT COUNT(DISTINCT Number) FROM GAMES;


(vi)SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES;
(vii) SELECT SUM(PrizeMoney) FROM GAMES;
(viii) SELECT DISTINCT Gcode FROM PLAYER;

14. (b) Consider the following tables ACTIVITY and COACH. Write SQL commands for
the statements (i) to (iv) and give outputs for SQL queries (v) to (viii)
SP2

(i) To display the name of all activities with their Acodes in descending order.
(ii) To display sum of PrizeMoney for each of the Number of participants groupings (as
shown in column ParticipantsNum 10,12,16)
(iii) To display the coach’s name and ACodes in ascending order of ACode from
the table COACH
(iv) To display the content of the GAMES table whose ScheduleDate earliar than
01/01/2004 in ascending order of ParticipantNum.

(v) SELECT COUNT(DISTINCT ParticipantsNum) FROM ACTIVITY;


(vi)SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM ACTIVITY;
(vii) SELECT SUM(PrizeMoney) FROM ACTIVITY;
(viii) SELECT DISTINCT ParticipantNum FROM COACH;

15. (b) Consider the following tables ACTIVITY and COACH and answer the questions:
SP3

Write SQL commands for the flowing statements:


(i) To display the names of all activities with their Acodes in descending order.
(ii) To display sum of PrizeMoney for the Activities played in each of the Stadium
separately.
(iii) To display the coach's name and ACodes in ascending order of ACode from
the table COACH
(iv) To display the content of the Activity table whose ScheduleDate earlier than
01/01/2004 in ascending order of ParticipantsNum.

Give the output of the following SQL queries:


(i) SELECT COUNT(DISTINCT ParticipantsNum) FROM ACTIVITY;
(ii) SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM ACTIVITY;
(iii) SELECT Name,ActivityName FROM ACTIVITY A,COACH C
WHERE A.Acode=C.Acode AND A.ParticipantsNum=10;
(iv) SELECT DISTINCT Acode FROM COACH;

16. (b) Consider the following tables Stationary and Consumer. Write SQL commands for
the statement (i) to (iv). 2013 S. P. 1

(i) To display the details of those consumers whose Address is Delhi.


(ii) To display the details of Stationary whose Price is in the range of 8 to 15. (Both Value
included)
(iii) To display the ConsumerName, Address from Table Consumer, and Company and Price
from table Stationary, with their corresponding matching S_ID.
(iv) To increase the Price of all stationary by 2.

Write the output for SQL queries (v) to (viii):


(v) SELECT DISTINCT Address FROM Consumer;
(vi) SELECT Company, MAX(Price), MIN(Price), COUNT(*) from Stationary GROUP BY
Company;
(vii) SELECT Consumer.ConsumerName, Stationary.StationaryName, Stationary.Price
FROM
Strionary, Consumer WHERE Consumer.S_ID=Stationary.S_ID;
(viii) Select StationaryName, Price*3 From Stationary;

17. (b) Consider the following tables EMPLOYEES and EMPSALARY. Write SQL
commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
2013 S.P. 2
(i) To display Firstname, Lastname, address and city of all employees leaving in Paris from
the table EMPLOYEES.
(ii) To display the content of EMPLOYEES table in descending order of Firstname.
(iii) To display the Firstname , Lastname, and total salary of all Managers from the
tablesEMPLOYEES and EMPSALARY, where total salary is calculated as SALARY +
BENEFITS
(iv) To display the maximum salary among Managers and Clerks from the table
EMPSALARY.

(v) SELECT FIRTNAME,SALARY FROM EMPLOYEES, EMPSALARY WHERE


DESIGNATION ='Salesman' AND EMPLOYEES.EMPID = EMPSALARY.EMPID;
(vi) SELECT COUNT(DISTINCT DESIGNATION) FROM EMPSALARY;
(vii) SELECT DESIGNATION,SUM(SALARY) FROM EMPSALARY GROUP BY
DESIGNATION HAVING COUNT(*)>2;
(viii) SELECT SUM(BENEFITS) FROM EMPLOYEES WHERE DESIGNATION =
'Clerk';

18. (b)Consider the following table Organisation and Grossincome and answer (I) and (II)
part of the question: 2013 S.P. 3
(I) Write SQL commands for the following statements:
(i) To display the details of all MEMBERS OF ORGANISATION in descending order of
DOJ.
(ii) To display NAME and POST of those MEMBERS whose SGRADE is either D002 or
D003.
(iii) To display the content of all the ORGANISATION table, whose DOJ is in between 09-
Feb-2006 and 08-Aug-2009.
(iv) To add a new row with the following 2007, ‘RUDRA’, ‘SALES INCHARGE’,
‘D002’,’26-Sep-2011’, ’26-Sept-1983’

(II) Give the output of the following SQL queries :


(i) SELECT COUNT(SGRADE), SGRADE FROM ORGANISATION GROUP BY
SGRADE;
(ii) SELECT MIN(DOB), MAX(DOJ) FROM ORGANISATION;
(iii) SELECT NAME,SALARY FROM ORGANISATION O, GROSSINCOME G
WHERE O.SGRADE=G.SGRADE AND O.ECODE<2003;
(iv) SELECT SGRADE, SALARY+HRA FROM GROSSINCOME WHERE
SGRADE=’D002’

19. (b)Consider the following tables SCHOOL and ADMIN. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
2013 S.P. 4
(i) To display TEACHERNAME, PERIODS of all teachers whose periods less than 25.
(ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and
ADMIN whose gender is male.
(iii) To display number of teachers in each subject wise.
(iv) To display CODE, TEACHERNAME and SUBJECT of all teachers who have joined the
school after 01/01/1999.

(v) SELECT MAX (EXPERIENCE), SUBJECT FROM SCHOOL GROUP BY SUBJECT;


(vi) SELECT TEACHERNAME, GENDER FROM SCHOOL, ADMIN WHERE
DESIGNATION = ‘COORDINATOR’ AND SCHOOL.CODE=ADMIN.CODE;
(vii) SELECT DESIGNATION, COUNT (*) FROM ADMIN GROUP BY DESIGNATION
HAVING COUNT (*) <2;
(viii) SELECT COUNT (DISTINCT SUBJECT) FROM SCHOOL;

Consider the following table named EXAM with details of marks. Write command of MySQL for (i)
to (iv) and output for (v) to (vii).

Table EXAM
Ano sName Percentage section Stream
R001
R002
R003
R004
R005
(i) To display all information of the students of humanities in descending order of
percentage.

Ans: select * from exam where stream='Humanities' order by percentage desc;

(ii) To display Adno, Name, Percentage and Stream of those students whose name is less
than 6 characters long.

Ans: select Adno,Sname,Percentage, Stream from exam where length(SName)<6;


(iii) To add another column Bus_Fees with datatype and size as Decimal(8,2).

Ans : alter table exam add column (bus_fees Decimal(8,2));

(iv) To increase percentage by 2% of all the Humanities students.

i. update exam set percentage=percentage+2 where stream='Humanities';


(v) SELECT COUNT(*) FROM EXAM;
(VI) SELECT SName, Percentage FROM EXAM WHERE Name LIKE “N%”;
(vii) SELECT ROUND (Percentage ,0) FROM EXAM WHERE Adno=“R005”;

drop table exam;

create table exam

adno char(5),

SName Varchar(20),

Percentage float(10,2),

section varchar(5),

Stream varchar(20)

);

insert into exam values ('R001','Sushant',90.2,'12-A','Science');


insert into exam values ('R002','Vaidyanath',80.5,'12-B','Humanities');

insert into exam values ('R003','Miara',68.9,'12-B','Science');

insert into exam values ('R004','Niara',96.0,'12-A','Commerce');

insert into exam values ('R005','Shinjini',88.9,'12-A','Commerce');

You might also like