Database Test 1
Database Test 1
1.Consider the following tables VEHICLE and TRAVEL. Answer the following questions: 8
Note:
1. To display CNO, CNAME, TRAVELDATE from the table TRAVEL in descending order of CNO.
2. To display the CNAME of all customers from the table TRAVEL who are travelling by vechicle with code Vo 1 or
Vo2
3. To display the CNO and CNAME of those customers from the table TRAVEL who travelled between ‘2015-12-
31’ and ‘2015-05-01’.
4. To display all the details from table TRAVEL for the customers, who have travel distacne more than 120 KM in
ascending order of NOE
5. SELECT COUNT (*), VCODE FROM TRAVEL GROUP BY VCODE HAVING COUNT (*) > 1;
6. SELECT DISTINCT VCODE FROM TRAVEL :
7. SELECT A.VCODE, CNAME, VEHICLETYPE FROM TRAVEL A, VEHICLE B WHERE A. VCODE = B.
VCODE and KM < 90;
8. SELECT CNAME, KM*PERKM FROM TRAVEL A, VEHICLE B WHERE A.VCODE = B.VCODE AND A.
VCODE ‘V05’;
2. Write SQL qureries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the tables TRANSPORT
and TRIE 8
Note:
Note:
NO is Driver Number
KM is Kilometer travelled
NOP is number of travellers travelled in vehicle
TDATE is Trip Date
1. To display NO, NAME, TDATE from the table TRIP in descending order of NO.
2. To display the NAME of the drivers from the table TRIP who are traveling by transport vehicle with code 101 or
103.
3. To display the NO and NAME of those drivers from the table TRIP who travelled between ‘2015-02-10’ and
‘2015-04-01’.
4. To display all the details from table TRIP in which the distance travelled is more than 100 KM in ascending order
of NOP
5. SELECT COUNT (*), TCODE From TRIP
GROUP BY TCODE HAVNING COUnT (*) > 1;
6. SELECT DISTINCT TCODE from TRIP;
7. SELECT A.TCODE, NAME, TTYPE
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND KM < 90;
8. SELECT NAME, KM *PERKM
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND A. TCODE = 105′;
3.Write SQL commands for the queries (i) to (iv) and output for (v) to (viii) based on the tables Watches’ and Sale
given below. 7
1. TO DISPLAY ALL THE DETAILS OF THOSE WATCHES WHOSE NAME ENDS WITH ‘TIME’
2. TO DISPLAY WATCH’S NAME AND PRICE OF THOSE WATCHES WHICH HAVE PRICE RANGE IN
BE-TWEEN 5000-15000.
3. TO DISPLAY TOTAL QUANTITY IN STORE OF UNISEX TYPE WATCHES.
4. TO DISPLAY WATCH NAME AND THEIR QUANTITY SOLD IN FIRST QUARTER;
5. SELECT MAX (PRICE), MIN(QTY_STORE) FROM WATCHES;
6. SELECT QUARTER, SUM(QTY SOLD) FROM SALE GROUP BY QUARTER;
7. SELECT WATCH_NAME, PRICE, TYPE FROM WATCHES W, SALE S WHERE W. WAT£H1D!
=S.WATCHID; (viii) SELECT WATCH_NAME, QTYSTORE, SUM (QTY_SOLD), QTY_STORESUM
(QTYSOLD) “STOCK” FROM WATCHES W, SALE S WHERE W. WATCHID = S.WATCHID GROUP BY
S.WATCHID;
4. . Consider the table Watches given below and write the output of the SQL queries
that follow: 3
5.Consider the following tables EMPLOYEE and DEPARTMENT and answer (a) and (b) parts of this question. 12
(i)To display all DepName along with the DepCde in descending order of DepCde.
(ii)To display the average age, maximum salary of Employees in each DepCode
(iii)To display the average age of Employees in DepCde as 103.
(iv)To display the name of DepHead of the Employee named “Sanjeev P”
(v)To display all DepName along with the DepCde in descending order of
DepCde.
(vi)To display the details of all employees who has joined before 2007 from EMPLOYEE
table.To
(vii)display the details of all employees who has joined after 2007 from EMPL-
OYEE table.
(viii)To display code, name, department, head of the department, salary, joining
date of employee “Sanjeev P”
1. Give a suitable example of a table with sample data and illustrate Primary and Alternate Keys in it.
2. Write SQL commands for the following statements:
7.(i)Write SQL code to delete the record(s) from STUDENT table for the student who has got less thjan 34 mark.1
(ii)Write SQL code to increase salary of each employee by 1700 who works in “R&D” department in Employee table.1