0% found this document useful (0 votes)
79 views

SQL

This document contains 6 questions with SQL queries and commands related to various tables. Question 1 involves the TEACHER table and asks to list teachers by department, gender, date of admission, and insert a new row. Question 2 involves the GRADUATE table and asks to list names by division, display a report on name, stipend, subject, and yearly stipend amount, count students by subject, and insert a new row. Question 3 involves the SPORTS table and asks to list names by game grade, display number of students by game/grade, list names by same game, list games by starting letter, and update marks for students.

Uploaded by

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

SQL

This document contains 6 questions with SQL queries and commands related to various tables. Question 1 involves the TEACHER table and asks to list teachers by department, gender, date of admission, and insert a new row. Question 2 involves the GRADUATE table and asks to list names by division, display a report on name, stipend, subject, and yearly stipend amount, count students by subject, and insert a new row. Question 3 involves the SPORTS table and asks to list names by game grade, display number of students by game/grade, list names by same game, list games by starting letter, and update marks for students.

Uploaded by

Kojo Ti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Q.

1 Write the SQL commands for the i) to iv) and write the output of the (v) on the basis of table
TEACHER.

Table:TEACHER

No. Name Age Department Dateofadm 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 37/06/98 30000 M

7 Shivam 44 Computer 25/02/97 21000 M

8 Shalakha 33 Maths 31/07/97 20000 F

i) To show all information about the 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 admission 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’

Q.2
TABLE : GRADUATE
S.NO NAME STIPEND SUBJECT AVERAGE DIV.
1 KARAN 400 PHYSICS 68 I
2 DIWAKAR 450 COMP. Sc. 68 I
3 DIVYA 300 CHEMISTRY 62 I
4 REKHA 350 PHYSICS 63 I
5 ARJUN 500 MATHS 70 I
6 SABINA 400 CEHMISTRY 55 II
7 JOHN 250 PHYSICS 64 I
8 ROBERT 450 MATHS 68 I
9 RUBINA 500 COMP. Sc. 62 I
10 VIKAS 400 MATHS 57 II

1.List the names of those students who have obtained I DIV sorted by NAME.

2.Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the STIPEND is paid every month.

3.To count the number of students who are either PHYSICS or COMPUTER SC graduates.
4.To insert a new row in the GRADUATE table:
11,”KAJOL”, 300, “computer sc”, 75, 1

Q.3 Write SQL command for (i) to (vii) on the basis of the table SPORTS
Table: SPORTS

Student NO Class Name Game1 Grade Game2 Grade2


10 7 Sammer Cricket B Swimming A
11 8 Sujit Tennis A Skating C
12 7 Kamal Swimming B Football B
13 7 Venna Tennis C Tennis A
14 9 Archana Basketball A Cricket A
15 10 Arpit Cricket A Atheletics C

(a) Display the names of the students who have grade ‘C’ in either Game1 or
Game2 or both.
(b) Display the number of students getting grade ‘A’ in Cricket.
(c) Display the names of the students who have same game for both Game1 and
Game2.
(d) Display the games taken up by the students, whose name starts with ‘A’.
(e) Assign a value 200 for Marks for all those who are getting grade ‘B’ or grade ‘A’
in both Game1 and Game2.
Q.4

Employees

Empid Firstname Lastname Address City


010 Ravi Kumar Raj nagar GZB
105 Harry Waltor Gandhi nagar GZB
152 Sam Tones 33 Elm St. Paris
215 Sarah Ackerman 440 U.S. 110 Upton
244 Manila Sengupta 24 Friends street New Delhi
300 Robert Samuel 9 Fifth Cross Washington
335 Ritu Tondon Shastri Nagar GZB
400 Rachel Lee 121 Harrison St. New York
441 Peter Thompson 11 Red Road Paris
EmpSalary

Empid Salary Benefits Designation


010 75000 15000 Manager
105 65000 15000 Manager
152 80000 25000 Director
215 75000 12500 Manager
244 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman
441 28000 7500 salesman
Write the SQL commands for the following :

(i) To show firstname,lastname,address and city of all employees living in paris


(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
Employee and empsalary , where total salary is calculated as salary+benefits.
(iv) To display the maximum salary among managers and clerks from the table Empsalary.

Q 5. Study the following table and then answer the given questions:
Table : SchoolBus

Rtno Area_covered Capacity Noofstudents Distance Transporter Charges


1 Vasant kunj 100 120 10 Shivamtravels 100000
2 Hauz Khas 80 80 10 Anand travels 85000
3 Pitampura 60 55 30 Anand travels 60000
4 Rohini 100 90 35 Anand travels 100000
5 Yamuna Vihar 50 60 20 Bhalla Co. 55000
6 Krishna Nagar 70 80 30 Yadav Co. 80000
7 Vasundhara 100 110 20 Yadav Co. 100000
8 Paschim Vihar 40 40 20 Speed travels 55000
9 Saket 120 120 10 Speed travels 100000
10 Jank Puri 100 100 20 Kisan Tours 95000
(a) To show all information of students where capacity is more than the no of student in order of
Rtno.
(b) To show area_covered for buses covering more than 20 km., but charges less then 80000.
(c) To show transporter wise total no. of students traveling.
(d) Add a new record with following data:
(11, “ Moti bagh”,35,32,10,” kisan tours “, 35000)

Q 6. Consider the following tables PRODUCT and answer (b) and (c) part of this question

Relation :PRODUCT

PCODE PNAME COMPANY PRICE STOCK MANUFACTURE WARRANTY


P001 TV BPL 10000 200 12-JAN-2008 3
P002 TV SONY 12000 150 23-MAR-2007 4
P003 PC LENOVO 39000 100 09-APR-2008 2
P004 PC COMPAQ 38000 120 20-JUN-2009 2
P005 HANDYCAM SONY 18000 250 23-MAR-2007 3
(a) Write MySQL commands for following Statements
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 of price and stock.
iv. To show number of products from each company.
v. To count the number of PRODUCTS which are manufactured in 2009.
7. Study the following table STAFF and Salary and write MySQL command for the questions (i)
to (iv)and give output for the (v) to(vi)

TABLE: STAFF

ID Name DEPT SEX EXPERIENCE


101 Siddharat Sales M 12
104 Raghav Finance M 6
107 Naman Research M 10
114 Nupur Sales F 3
109 Janvi Finance F 9
105 Rama Research M 10
117 James Sales F 3
111 Binoy finance F 12
130 Samuel Sales M 15

TABLE: SALARY

ID Basic Allowance Commission


101 15000 1500 800
104 17000 1200 500
107 16000 1000 200
114 20000 2200 550
109 18000 1000 250
105 15000 1200 150
117 18000 1700 100
111 20000 1500 300
130 18000 1200 500

(i) Display NAME of all the staff who is in SALES having more than 10 year experience from
the table staff.
(ii) Display the average Basic Salary of all staff working in ”Finance” department using the table
staff and salary.
(iii)Display the minimum ALLOWANCE of female staff.
(iv) Display the highest commission among all male staff

(8) Write the SQL commands for the i) to iv) and write the output of the v) and vi) on the basis of
table TEACHER.

Table:TEACHER

No. Name Age Department Dateofadm 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 37/06/98 30000 M

7 Shivam 44 Computer 25/02/97 21000 M

8 Shalakha 33 Maths 31/07/97 20000 F

v) To show all information about the teacher of History department.

vi) To display the list of all male teachers who are in Maths department.

vii) To display Names, Age and Sex of all teachers with their date of admission in descending
order.
viii) To insert a new row in the TEACHER table with the following data:
9,’Raja’, 26,’Computer’, {13/05/95}, 23000,’M’

9. Consider the table Flight given below, write command in SQL for (1) to (4) and output for (5) to (

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.

(10) Consider the following table Customer of On-line Trading with details of customers. Write MySQL
command for (a) to (d) and output for (e) to (h).
Table: CUSTOMER

CustNo CustName City Product Make Amount

101 T. Shankar Mumbai Smart Phone Samsung 18500

102 Ravindra Nath Lucknow LCD TV LG 22500

103 Abdul Kanpur Smart Phone LG 19000

104 Shamsher Singh Dehradun Laptop HP 36500

105 Rosy Delhi LCD TV Samsung 18500

106 Hemant Kumar Delhi Camera Sony 12500

a) To display customer name, city and amount of those customers whose name is greater than
5 characters long.
b) To change ‘LG’ with ‘Lifes Good’ in product column.
c) To increase size of CustName as 40 characters.
d) To display CustName, Product and TaxAmount as 3% of Amount.

11. Consider the table Hospital given below. Write commands in MySQL for (i) to (iv) and
output for (v) to (vii).

No Name Age Department DateOfAdm Charges Sex

1 Sandeep 64 Surgery 23/02/97 400 F

2 Ravina 24 Orthopedic 20/01/98 200 F

3 Karan 45 Orthopedic 10/02/97 200 M

4 Tarun 12 Surgery 01/01/98 300 F

5 Zubin 36 ENT 12/01/98 250 M

6 Ketaki 16 ENT 12/02/98 300 F

7 Ankita 29 Cardiology 20/02/98 800 F

8 Zareen 45 Gynecology 22/02/98 400 F

9 Kush 19 Cardiology 13/01/97 800 M

10 Shailya 31 Medicine 19/02/97 400 F

(i) To show all information of patients who are in Orthopedic department from
hospital table in descending order of their age.
(ii) Increase the charges of male patient in ENT department by 4%.
(iii) Display a report listing name, age, charges and amount of charges including
VAT as 2% on charges, name the column as total charges.
(iv) To count the number of patients with Age < 30.
12-Write queries based on the following “EMP” Table:

EMP

Column name Data type Size Constraint


EMPNO Integer 4 digits Not Null
ENAME Varchar 25 characters Not Null
GENDER Char 1 Default M
DOB Date Not Null
DEPTNO Integer 2 Default 10
SAL Numeric 4 digits Null allowed
Primary Key is EMPNO

Sample Data in EMP Table:

EMPNO ENAME GENDER DOB DEPTNO SAL


1001 ROHAN M 2002-01-20 10 18500
1002 AMAR M 2001-03-20 11 18500
1003 SMRITI F 2004-11-25 10 19000
1004 RUMA F 2003-12-31 12 16500
1005 SUJAL M 2002-09-11 13 15500
….. …… . ……………… … ……
e) Write SQL query to create the EMP Table.
f) Write SQL query to increase the size of ENAME column to hold 30 characters.
g) Write SQL query to insert a row in the table.
h) Write SQL query to increase the SAL of all the female employees by 5% of existing
Salary.
i) Write SQL query to delete the record for empno 1006.

13) Consider the table FLIGHT given below. Write commands in SQL for (i) to (iv) and output for (v)
to (vii).

(i) Display details of all flights starting from Delhi.


(ii) Display details of flights that have more than 4 number of flights operating.
(iii) Display flight codes, starting place, destination, number of flights in descending order of number of
flights.

(iv) Display destinations along with flight codes of all the destinations starting with ‘A’.

You might also like