You are on page 1of 6

Maharaja Agrasen Model school CD-Block Pitam Pura, Delhi Class XII Computer Science SQL Assignment 1.

Consider the following tables EMPLOYEES and EMPSALARY. Write SQL commands for the statements (i) to (iv) and give outputs for SQL quires (v) to (viii). 6

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

(v) (vi) (vii) (viii)

SELECT FIRSTNAME,SALARY FROM EMPLOYEES,EMPSALARY WHERE DESTINATION = salesman AND EMPOLYEES.EMPID=EMPSALARY.EMPID; SELECT COUNT (DISTINT DESIGNATION ) FROM EMPSALARY SELECT DESIGNATION , SUM(SALARY) FROM EMPSALARY GROUP BY DESIGNATION HAVING COUNT(*)>2; SELECT SUM (BENEFITS) FROM EMPSALARY WHERE DESIGNATION=.Clerk.;

2. Consider the following relation TEACHER and SALARY. Write SQL commands for the statement (i) to (iv) and output from (v) to (viii). 6 TABLE: TEACHER TID FIRST_NAME LAST_NAME ADDRESS SUBJECT 010 Rohit Sharma 83, Lok Vihar English 105 Meeta Rathi 842, Rajauri Garden Physics 152 Seema Verma 33, Safdarganj Maths 215 Sarad Singh 440, Ashok Vihar Physics 244 Manish Sengupta 24, New Street Maths 300 Ram Gupta 9, Fifth Road Chemistry 355 Heena Jain 12, Friends Street Computer 400 Rachit Sharma 10, Paschim Vihar Computer 441 Punit Jain 11, Rohini Chemistry TABLE: SALARY TID 010 105 152 215 (i) (ii) (iii) SARARY BONUS DESIGNATION 7500 1500 PGT 8500 1500 PGT 6000 1200 TGT 7500 1500 PGT To display FIRST_NAME, LAST_NAME and SUBJECT of all teachers of PHYSICS subject To display all records in ascending order of LAST_NAME. To display the TID, FIRST_NAME and total SALARY of all PGT from the table TEACHER and SALARY, where total salary is calculated as SALARY + BONUS. (iv) To display the ADDRESS of teachers SUBJECT wise. (v) SELECT FIRST_NAME, SALARY FROM TEACHER, SALARY WHERE DESIGNATION=TGT AND TEACHER.TID = SALARY.TID; (vi) SELECT DISTINCT(DESIGNATION), MAX (SALARY) FROM SALARY (vii) SELECT FIRST_NAME, ADDRESS FROM TEACHER WHERE FIRST_NAME LIKE (S%); (viii) SELECT SUM (BONUS) FROM SALARY WHERE DESIGNATION=PGT; 3. Consider the following table LIBRARY. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). (6) (Answer the outputs by just considering the following table contents only)

Sl No. Title Author Subject Quantity Price 1 Data Structure Lipschute DS 4 320.00 2 Turbo C++ Robort Lafore Prog 3 213.00 3 COBOL Stern Prog 6 515.00 4 Basic for Beginners Norton Prog 2 430.00 5 Dbase Palmer DBMS 3 230.00 (i) To display the Title of all books with Price 100 and 300.(Both values included) (ii) To display Title and Author of all the books having type Prog. (iii) To display list of all the books with price more than 300 in ascending order of Quantity. (iv) To increase the price of all the items by 315 in the table LIBRARY. (v) SELECT MIN(price) FROM LIBRARY; (vi) SELECT SUM(Price * Quantity) FROM LIBRARY WHERE Quantity >3; (vii) SELECT COUNT(DISTINCT Subject) FROM LIBRARY; (viii) SELECT Subject ,MAX(Price),COUNT(*) FROM LIBRARY GROUP BY Subject; 4. 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) (6)

TABLE: EMPLOYEE EMPID 101 102 103 104 105 106 107 108 109 110 EMPNAME Sabeena Siva Ayaz Gayathri Poorna Giridhar Sindhu Suganya Hemanth Suprakya SECTION PRODUCTION ACCOUNTS INSPECTION PRODUCTION ACCOUNTS INSPECTION PRODUCTION ACCOUNTS PRODUCTION ACCOUNTS SEX F M M F F M F F M F EXPERIENCE 10 15 10 8 9 10 13 11 15 7

TABLE: SALARIES EMPID 101 103 105 SALARY 18000 23150 13120 INCENTIVE ALLOWANCE 1800 3100 2300 1325 1121 1240

106 107 109 110 i. ii.

12550 11145 18900 21400

1250 1100 1990 2100

1005 1290 1200 1312

iii. iv. v. vi. vii. viii.

Display EMPNAME of all staff who are in ACCOUNTS having more than 10 years experience from the table EMPLOYEE. Display the average PAY of all staff working in INSPECTION department using the tables EMPLOYEE and SALARIES. The total pay is calculated as PAY= SALARY +INCENTIVE+ ALLOWANCE. Display the minimum INCENTIVE of female staff. Display the highest ALLOWANCE among all male staff. SELECT count (*) from EMPLOYEE where SEX = F. SELECT EMPNAME, SECTION, ALLOWANCE from EMPLOYEE, SALARIES where SECTION = ACCOUNTS and EMPLOYEE.EMPID = SALARIES.EMPID. SELECT EMPNAME from EMPLOYEE where SECTION= INSPECTION and SEX=M Select count (distinct SECTION) from EMPLOYEE

5. Consider the following tables GAMES and PLAYER and answer (b) and (c) parts of this question: Table: GAMES GCode GameName Type Number PrizeMoney ScheduleDate 101 Carom Board Indoor 2 5000 23-Jan-2004 102 Badminton Outdoor 2 12000 12-Dec-2003 103 Table Tennis Indoor 4 8000 14-Feb-2004 105 Chess Indoor 2 9000 01-Jan-2004 108 Lawn Tennis Outdoor 4 25000 19-Mar-2004 Table: PLAYER PCode Name Gcode 1 Nabi Ahmad 101 2 Ravi Sahai 108 3 Jatin 101 4 Nazneen 103 (b) Write SQL commands for the flowing statements: 4 (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 Schedule Date. (iv) To display sum of PrizeMoney for each Type of GAMES (c) Give the output of the following SQL queries: 2 (i) SELECT COUNT(DISTINCT Number) FROM GAMES; (ii) SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES; (iii) SELECT Name, GameName FROM GAMES G, PLAYER P WHERE G.Gcode=P.Gcode AND G.PrizeMoney>10000; (iv) SELECT DISTINCT Gcode FROM PLAYER; 6. Study the following tables TOUR and ACCOMODATION and write SQL commands for the questions (i) to (iv) and give outputs for SQL queries (v) to (viii). 6 Table : TOUR

SNO STUNO 1 2 3 4 5 6 7 B01 B02 B03 B04 G01 G02 G03

NAME Aamir Salman Akshay Ranveer Shilpa Preeti

STD XII XII XI XI XII XII

JAIPUR LB MB LB UB LB MB

BARMER MB UB LB UB LB UB

POCKET 2000 2500 2000 1500 2500 1500 3500

Rani XI UB MB Table : ACCOMODATION STUNO ROOMNO FLOOR FOOD B01 B02 B03 B04 G01 G02 201 201 202 202 402 402 II II II II IV IV Veg N Veg N Veg Veg Veg N Veg

G03 403 IV Veg Note : In Stuno B stands for Boys and G stands for Girls JAIPUR refers Train to JAIPUR and BARMER refers Train to BARMER LB Lower Berth, MB Middle Berth, UB Upper Berth i. Display the details of student who got lower berth in both Jaipur and Barmer train. ii. Display the name of students whose food choice is Veg. iii. Update the food type as N Veg for girls students. iv. Display the sum of pocket money of the students standard wise. v. select tour.stuno, name, roomno from tour, accomodation where accomodation.stuno = tour.stuno; vi. select count(pocket), sum (pocket) from tour, accomodation where tour.stuno = accomodation.stuno AND food ='Veg'; vii. select distinct roomno from accommodation; viii. select max(pocket), min(pocket) from tour group by std; 7Consider the table Graduate given below and answer the questions : 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 9 10 (a) (b) (c.) (d) (e)

ROBERT 450 MATHS 68 I RUBINA 500 COMP. Sc. 62 I VIKAS 400 MATHS 57 II List the names of those students who have obtained DIV I sorted by NAME. Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year assuming that the STIPEND is paid every month. To count the number of students who are either PHYSICS or COMPUTER SC graduates. To insert a new row in the GRADUATE table: 11,KAJOL, 300, COMP. SC., 75, 1 Give the output of following sql statement based on table GRADUATE: (i) Select MIN(AVERAGE) from GRADUATE where SUBJECT=PHYSICS; (ii) Select SUM(STIPEND) from GRADUATE WHERE div=2; (iii) Select AVG(STIPEND) from GRADUATE where AVERAGE>=65; (iv) Select COUNT(distinct SUBDJECT) from GRADUATE; Assume that there is one more table GUIDE in the database as shown below: Table: GUIDE MAINAREA ADVISOR PHYSICS VINOD COMPUTER SC ALOK CHEMISTRY RAJAN MATHEMATICS MAHESH What will be the output of the following query: SELECT NAME, ADVISOR FROM GRADUATE,GUIDE WHERE SUBJECT= MAINAREA;

(f)

You might also like