QuesAns Print Page – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
Q&A CBSE12A-2019-C05A #7074

Question:

Write SQL queries for (i) to (iv) and write outputs for SQL queries (v) to (viii), which are based on the table given below:

Table: TRAINS

TNO TNAME START END
11096 Ahimsa Express Pune Junction Ahmedabad Junction
12015 Ajmer Shatabdi New Delhi Ajmer Junction
1651 Pune Hbj Special Pune Junction Habibganj
13005 Amritsar Mail Howrah Junction Amritsar Junction
12002 Bhopal Shatabdi New Delhi Habibganj
12417 Prayag Raj Express Allahabad Junction New Delhi
14673 Shaheed Express Jaynagar Amritsar Junction
12314 Sealdah Rajdhani New Delhi Sealdah
12498 Shane Punjab Amritsar Junction New Delhi
12451 Shram Shakti Express Kanpur Central New Delhi
12030 Swarna Shatabdi Amritsar Junction New Delhi

Table:PASSENGERS

PNR TNO PNAME GENDER AGE TRAVELDATE
P001 13005 R N AGRAWAL MALE 45 2018-12-25
P002 12015 P TIWARY MALE 28 2018-11-10
P003 12015 S TIWARY FEMALE 22 2018-11-10
P004 12030 S K SAXENA MALE 42 2018-10-12
P005 12030 S SAXENA FEMALE 35 2018-10-12
P006 12030 P SAXENA FEMALE 12 2018-10-12
P007 13005 N S SINGH MALE 52 2018-05-09
P008 12030 J K SHARMA MALE 65 2018-05-09
P009 12030 R SHARMA FEMALE 58 2018-05-09

(i)  To display details of all Trains which Start from New Delhi.

(ii) To display the PNR, PNAME, GENDER and AGE of all Passengers whose AGE is below 50.

(iii) To display total number of MALE and FEMALE Passengers.

(iv) To display details of all Passengers travelling in Trains whose TNO is 12015.

(v) SELECT MAX (TRAVELDATE), MIN(TRAVELDATE) FROM PASSENGERS WHERE GENDER = ‘FEMALE’;

(vi) SELECT END, COUNT(*) FROM TRAINS GROUP BY END HAVING COUNT(*)>1;

(vii) SELECT DISTINCT TRAVELDATE FROM PASSENGERS;

(viii) SELECT TNAME, PNAME FROM TRAINS T, PASSENGERS P WHERE T.TNO=P.TNO AND AGE BETWEEN 50 AND 60;

Answer:

i) SELECT * FROM TRAINS WHERE START=”New Delhi”;

ii) SELECT PNR, PNAME, GENDER, AGE FROM PASSENGERS WHERE AGE < 50;

iii) SELECT GENDER, COUNT(GENDER) FROM PASSENGERS GROUP BY GENDER;

iv) SELECT * FROM PASSENGERS WHERE TNO=12015;

v)
MAX(TRAVELDATE) MIN(TRAVELDATE)
2018-11-10                     2018-05-09

vi)

END                         COUNT(*)
Habibganj               2
Amritsar Junction 2
New Delhi               4

vii)

DISTINCT TRAVELDATE
2018-12-25
2018-11-10
2018-10-12
2018-05-09

viii)

TNAME                             PNAME
Amritsar Mail                  N S SINGH
Swarna Shatabdi            R SHARMA