0% found this document useful (0 votes)
29 views

Class Revision SQL

The document provides SQL practice questions and answers related to tables such as TRAVEL, VEHICLE, ADMIN, SCHOOL, TRIP, and TRANSPORT. It includes questions about selecting, filtering, ordering, aggregating and joining data from the tables. Additional questions involve altering a table and using wildcards in queries.

Uploaded by

KHOUSHIK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Class Revision SQL

The document provides SQL practice questions and answers related to tables such as TRAVEL, VEHICLE, ADMIN, SCHOOL, TRIP, and TRANSPORT. It includes questions about selecting, filtering, ordering, aggregating and joining data from the tables. Additional questions involve altering a table and using wildcards in queries.

Uploaded by

KHOUSHIK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL Practice - I

• PERKS is Freight Charges per kilometer.


• Km is kilometers Travelled
• NOP is number of passangers travelled in vechicle.

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 Vo1 or Vo2
3. To display the CNO and CNAME of those customers from the table TRAVEL who travelled
between ‘2015-1231’ 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. Consider the following tables SCHOOL and ADMIN and answer this question :
Give the output the following SQL queries :

1. Select Designation Count (*) From Admin Group By Designation Having Count (*)
<2;
2. SELECT max (EXPERIENCE) FROM SCHOOL;
3. SELECT TEACHER FROM SCHOOL WHERE EXPERIENCE >12 ORDER BY
TEACHER;
4. SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;
3.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.

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′;
Answer
1. SELECT NO, NAME, TDATE FROM TRIP ORDER BY NO;
2. SELECT NAME FROM TRIP WHERE TCODE = 101 OR TCODE = 103;
3. SELECT NO AND NAME FROM TRIP WHERE ‘2015-02-10’ < TDATE < ‘2015-04-
01’;
4. SELECT NO, NAME, TDATE, KM, TCODE FROM TRIP WHERE KM >100 ORDER
BY NOP;
5. TO DISPLAY THE MORE THAN ONE COUNT OF TCODE FROM THE TABLE
TRIP
6. TO DISPALY SEPERATE TCODE OF TABLE TRIP
7. TO DISPAY THE NAME AND CODE OF THOSE TRANS PORTERS, WHO HAVE
TRAVELLED MORE THAN 90 KMS.
8. TO DISPLAY THE NAME AND EXPENDITARE OF A TRANSPORTER WHO
HAVE TCODE AS 105.
3.Write SQL query to add a column total price with datatype numeric and size 10, 2 in a table
product.
Answer:
ALTER TABLE PRODUCT ADD TOTAL PRICE NUMBER (10,2).
4. Sonal needs to display name of teachers, who have “0” as the third character in their name.
She wrote the following query.
SELECT NAME FROM TEACHER WHERE NAME = “$$0?”;
But the query is’nt producing the result. Identify the problem.
Answer:
The wildcards are incorrect. The corrected query is SELECT NAME FROM TEACHER
WHERE NAME LIKE ‘_ _0%’.

You might also like