0% found this document useful (0 votes)
30 views4 pages

SQL Questions

The document provides SQL queries to retrieve information from two tables, TEACHER and FLIGHTS. It lists SQL queries that should be written for tasks (a) through (f) on the TEACHER table and the expected outputs for part (g). It then lists similar tasks (i) through (iv) on the FLIGHTS and FARES tables and expected outputs for parts (v) and (vi).

Uploaded by

Shri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
30 views4 pages

SQL Questions

The document provides SQL queries to retrieve information from two tables, TEACHER and FLIGHTS. It lists SQL queries that should be written for tasks (a) through (f) on the TEACHER table and the expected outputs for part (g). It then lists similar tasks (i) through (iv) on the FLIGHTS and FARES tables and expected outputs for parts (v) and (vi).

Uploaded by

Shri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

WRITE THE SQL COMMANDS FOR (a) TO (f) AND WRITE THE

OUTPUTS FOR (g) ON THE BASIS OF THE FOLLOWING TABLE.


TABLE : TEACHER
SLNO NAME AGE DEPARTMENT DATEOFJOIN SALARY SEX
1 JUGAL 34 COMPUTER 10-JAN-97 12000 M
2 SHARMILA 31 HISTORY 24-MAR-98 20000 F
3 SANDEEP 32 MATHS 12-DEC-96 30000 M
4 SANGEETA 35 HISTORY 01-JUL-99 40000 F
5 RAKESH 42 MATHS 05-SEPT-97 25000 M
6 SHYAM 50 HISTORY 27-JUN-98 30000 M
7 SHIV OM 44 COMPUTER 25-FEB-97 21000 M
8 SHALAKHA 33 MATHS 31-JUL-97 20000 F
(a) To show all information about the teacher of History department.
(b) To list the name of female teachers who are in Maths department.
(c) To list names of all teachers with their date of joining in ascending
order.
(d) To display Teacher’s Name, Salary, age for male teachers only.
(e) To count the number of teachers with age>23.
(f) To insert a new row in the TEACHER table with the following data.
9, ‘RAJA’, 26, ‘COMPUTER’, ’13-MAY-95’, 23000, ‘M’.
(g) (i) SELECT COUNT(DISTINCT DEPARTMENT) FROM TEACHER;
(ii) SELECT MAX(AGE) FROM TEACHER WHERE SEX=’F’;
(iii) SELECT AVG(SALARY) FROM TEACHER WHERE SEX=’M’;
(iv) SELECT SUM(SALARY) FROM TEACHER WHERE
DATEOFJOIN<’12-JUL-96’
Answers :
(a) SELECT * FROM TEACHER WHERE DEPARTMENT=’HISTORY’;
(b) SELECT NAME FROM TEACHER WHERE DEPARTMENT=’MATHS’
AND SEX=’F’;
(c) SELECT NAME FROM TEACHER ORDER BY DATEOFJOIN;
(d) SELECT NAME, SALARY, AGE FROM TEACHER WHERE SEX=’M’;
(e) SELECT COUNT(*) FROM TEACHER WHERE AGE>23;
(f) INSERT INTO TEACHER SET VALUES(9, ‘RAJA’, 26, ‘COMPUTER’,
’13-MAY-95’, 23000, ‘M’);
(g) (i) 3
(ii) 35
(iii) 24555.55
(iv) 23000.
WRITE THE SQL COMMANDS FOR (a) TO (d) AND WRITE THE
OUTPUTS FOR (g) & (h) ON THE BASIS OF THE FOLLOWING TABLE.
TABLE : FLIGHTS
FLNO STARGING ENDING NOOFFLIGHTS NOOFSTOPS
IC-301 MUMBAI DELHI 8 0
IC-799 BANGLORE DELHI 2 1
MC-101 INDORE MUMBAI 3 0
IC-302 DELHI MUMBAI 8 0
AM-812 KANPUR BANGLORE 3 1
IC-899 MUMBAI KOCHI 1 4
AM-501 DELHI TRIVANDRUM 1 4
MU-499 MUMBAI MADRAS 3 3
IC-701 DELHI AHMEDABAD 4 0
TABLE : FARES
FLNO AIRLINES FARES(Rs.) TAX %
IC-701 INDIAN AIRLINES 6500 10
MU-499 SAHARA 9400 5
AM-501 JET AIRWAYS 13450 8
IC-899 INDIAN AIRLINES 8300 4
IC-302 INDIAN AIRLINES 4300 10
IC-799 INDIAN AIRLINES 10500 10
MC-101 DECCAN AIRLINES 3500 4

(i) Display FLNO and NOOFFLITE from “KANPUR” to “BANGLORE”


from table FLIGHTS.

SELECT FLNO, NOOFFLIGHTS FROM FLOGHTS WHERE


STARTING=”KANPUR” AND ENDING=”BANGLORE”;
(ii) Arrange the contents of the table FLIGHTS in the ascending
order of FLNO.
SELECT * FROM FLIGHTS ORDER BY FLNO;

(iii) Display the FLNO and FARE to be paid for the flights from
“DELHI” to “MUMBAI” using table FLIGHTS and FARES, where the
fare to be paid = FARE + FARE * TAX%/100.

SELECT F.FLNO, R.FARE+R.FARE*(R.TAX%/100) FROM FLIGHTS F,


FARES R WHERE F.STARTING=”DELHI” AND F.ENDING=”MUMBAI”;

(iv) Display the minimum fare “INDIAN AIR LINES” is offering from
the table FARES.
SELECT MIN(FARE) FROM FARES WHERE AIRLINES=”INDIAN
AIRLINES”

(v) SELECT FLNO, NOOFFLIGHTS, AIRLINES FROM FLIGHTS, FARES


WHERE STARTING=”DELHI” AND FLIGHTS.FLNO=FARES.FLNO;

FLNO NOOFFLIGHTS AIRLINES


AM-501 1 JET AIRWAYS
IC-302 8 INDIAN AIRLINES
IC-701 4 INDIAN AIRLINES

(vi) SELECT COUNT(DISTINCT ENDING) FROM FLIGHTS;


COUNT (DISTINCT ENDING)
----------------------------------
7

You might also like