Sie sind auf Seite 1von 6

Q1.

Write an SQL command for the queries given, based on Table EMPDETS and LEAVE as shown below: Table BOOK
EMP_NO E01 E02 E03 E04 E05 E06 EMP_NAME Ahmed Hussain Ravinder Singh Jully Bhatt Shiva Mathur Sonia Jolly Sumita Singh DEPARTMENT Accts System System Accts Accts Purchase Table ISSUED EMP_NO E01 E04 E05 E06 Leaves 3 5 5 1 SALARY 15000 35000 20000 15000 12000 18000 EXPERIENCE 3 5 5 7 3 10

1. To display all employee names in descending order of salary. 2. Display the no. of employee whose salary > 15000 and experience > 5 years. 3. Display the average salary of each department. 4. Increase the salary of all employees of Accts Department by 1000. 5. Delete the employee details whose experience is less than 3 yr. 6. Insert a new row in leave with details E02,3.

Answers: 1. SELECT Emp_Name FROM EMPDETS ORDER BY SALARY desc; 2. SELECT count(*) FROM EMPDETS WHERE Salary>15000 AND Experience>5; 3. SELECT avg(salary) FROM EMPDETS GROUP BY Department; 4. UPDATE EMPDETS SET Salary=Salary+1000 WHERE Department=Accts; 5. DELETE FROM EMPDETS WHERE Experience<3; 6. INSERT INTO LEAVE VALUES(E02,3);

Q2. Write an SQL command for the queries given, based on Table BOOK and ISSUED as shown below: Table BOOK
BOOK_ID F0001 T0001 F0001 T0001 C0001 BOOK_NAME The Tears My First C++ Thunder Bolts Data Structure Fast Cook PUBLISHERS First Publisher RPB First Publisher TDH EPB Table ISSUED BOOK_ID T0001 C0001 F0001 QUANTITY_ISSUED 4 5 2 DATE_OF_ISSUE 12-Dec-99 12-Dec-99 11-Dec-99 PRICE 450 600 1200 230 100 TYPE Fiction Text Fiction Text Cookery QUANTITY 5 12 15 12 13

1. To show book_name, price and val (=price*quantity) of First Publisher from the table book 2. To count records of Text type whose quantity is more than 10 3. To display the name and price from book in ascending order of their price 4. To increase the price of all books of EPB publishers by 10% 5. To insert a new row in the table issued having the following data ("F0003",1,10Dec-99) 6. Count the number of books in each type from the table book 7. To display the book_id, book_name and quantity_issued for all books which have been issued (Use both tables) 8. To include a new column date_of_purchase of date type in table book.

Answers: 1. SELECT book_name, price, price*quantity val FROM book WHERE publishers=First Publisher; 2. SELECT type, COUNT(*) Quantity more than 10 FROM book WHERE quantity>10 AND type=Text; 3. SELECT name, price FROM book ORDER BY price ASC; 4. UPDATE book SET price=1.1*price WHERE publishers=EPB;

5. INSERT INTO issued VALUES (F0003, 1, 10-Dec-99); 6. SELECT type, COUNT(*) FROM book GROUP BY type; 7. SELECT book.book_id, book_name, quantity_issued FROM book, issued WHERE book.book_id=issued.book_id; 8. ALTER TABLE book ADD (date_of_purchase DATE);

Q3. Write an SQL command for the queries for the questions given, based on a Table TRAIN shown below: Table TRAIN TRAINNO 1 2 3 4 5 6 7 NAME ANU SAGAR SAMIR GAURAV KRIPAL ANKUR PRIYA CLASS I AC-CHAIR AC-I AC-II I II AC-II SEATNO 11 34 78 23 3 6 2 AGE 16 43 18 17 25 20 11 FARE 700 1300 9000 600 1700 500 1200

1. To display the name and seatno where class is II and age is more than 20 2. To display trainno and seatno where the fare is between 900 and 1300 3. To display the list of passengers in ascending order of trainno 4. To display the highest and lowest amount paid as fare 5. To display the number of passengers in each class 6. Insert a new row in the above table with the details (9,"Ajay","II",19,20,500) 7. Display all distinct classes

Answers: 1. SELECT name, seatno FROM train WHERE class=II AND age>20; 2. SELECT trainno, seatno FROM train WHERE fare BETWEEN 900 AND 1300; 3. SELECT * FROM train ORDER BY trainno ASC; 4. SELECT MAX(fare) Maximum Fare, MIN(fare) Minimum Fare FROM train; 5. SELECT class, COUNT(*) FROM train GROUP BY class; 6. INSERT INTO train VALUES (9, Ajay, II, 19, 20, 500); 7. SELECT class FROM train GROUP BY class;

Q4. Write an SQL command for the queries for the questions given, based on the Table SHOP, shown below. Table SHOP NO 1 2 3 4 5 6 SHOPNAME S.M. Sons Dharohar Kriti Art Ripple Best Stores Crystal SALE 250000 500000 300000 380000 456000 290000 AREA West South North North East South C_PERC 68.6 81.8 79.8 88.0 92.0 66.7 RATING C A B B A A CITY Delhi Mumbai Kolkatta Mumbai Delhi Kolkatta

1. Show all the names of all shops which are in the South area and c_perc < 75 2. To display the number of shops in each city 3. To display a list of all the shops with sale > 300000 in ascending order of shopname 4. To display shopname, area and rating for only those shops whose sale is between 350000 and 400000 (including both values) 5. To count the number of shops whose rating is A 6. To show the average sale of each area

Answers: 1. SELECT shopname FROM shop WHERE area=South AND c_perc < 75; 2. SELECT city, COUNT(*) FROM shop GROUP BY city; 3. SELECT * FROM shop WHERE sale>300000 ORDER BY shopname ASC; 4. SELECT shopname, area, rating FROM shop WHERE sale BETWEEN 350000 AND 400000; 5. SELECT rating, COUNT(*) FROM shop WHERE rating=A; 6. SELECT area, AVG(sale) FROM shop GROUP BY area;

Q5. Write an SQL command for the queries for the questions given based on a Table STUDENT shown below. Table STUDENT NO 1 2 3 4 5 6 NAME Neha Damini Gaurav Anu Vikas Rubina STIPEND 450.00 400.00 250.00 300.00 500.00 450.00 STREAM Medical Commerce Humanities Commerce Non-medical Non-medical AVGMARK 89.2 78.5 64.4 67.5 92.0 88.5 GRADE A B C C A A CLASS 11C 12B 11A 12B 12A 12A

1. To display the names of all students who are in Non-medical stream and grade is A 2. To display average stipend of all the students scoring avgmark < 70.0 of each stream 3. To display list of all the students with stipend > 350.00 in ascending order of name 4. To display details with name, totmarks for each student in the table. totmarks are calculated as avgmarks*5 5. To count the total number of students in each stream

Answers: 1. SELECT name FROM student WHERE stream=Non-medical AND grade=A; 2. SELECT stream, AVG(stipend) FROM student WHERE avgmark<70.0; 3. SELECT * FROM student WHERE stipend>350.00 ORDER BY name asc; 4. SELECT name, avgmarks*5 totmarks FROM student; 5. SELECT stream, COUNT(*) FROM student GROUP BY stream;

Das könnte Ihnen auch gefallen