SQL (Structure Query Language)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

SQL (Structure Query Language)

1. Write queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are
based on the tables.
Table: Vehicle
VCODE VEHICLETYPE PERKM  PERKS is Freight Charges per kilometer.
V01 VOLVO BUS 150  Km is kilometers Travelled
V02 AC DELUXE BUS 125  NOP is a number of passengers travelled in vehicle.
V03 ORDINARY BUS 80
V04 SUV 30
V05 CAR 18

Table: Travel
CNO CNAME TRAVELDATE KM VCODE NOP
101 K. Niwal 2015-12-13 120 V01 32
103 Fredrick Sym 2016-03-21 450 V03 45
105 Hitesh Jain 2016-04-23 80 V02 42
102 Ravi Anish 2016-01-13 65 V02 40
107 John Malina 2015-02-10 90 V04 2
104 Sahanubhuti 2016-01-28 100 V05 4
106 Ramesh Jaya 2016-04-06 120 V01 25

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 traveling by vehicle with
code V01 or V02
3. To display the CNO and CNAME of those customers from the table TRAVEL who traveled between
‘2015-1231’ and ‘2015-05-01’.
4. To display all the details from table TRAVEL for the customers, who have travel distances more
than 120 KM in ascending order of NOP
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’;

RAMAKRISHNA ACADEMY 7003793770


1
SQL (Structure Query Language)

ANSWER
1. SELECT CNO, CNAME, TRAVELDATE FROM TRAVEL ORDER BY CNO DESC ;
2. SELECT CNAME FROM TRAVEL WHERE VCODE = ‘V01’ OR VCODE = ‘V02’;
OR
SELECT CNAME FROM TRAVEL VCODE IN (‘V01’, ‘V02’) ;
3. SELECT CNO, CNAME from TRAVEL WHERE TRAVELDATE >= ‘2015-05-01’ AND TRAVELDATE <== ‘2015-12-31’ ;
OR
SELECT CNO, CNAME from TRAVEL WHERE TRAVELDATE BETWEEN ‘2015-05-01’ AND ‘2015-12-31’ ;
OR
SELECT CNO, CNAME FROM TRAVEL WHERE TRAVELDATE < = ‘2015-12-31’ AND TRAVELDATE > = ‘2015-05-01’ ;
OR
SELECT CNO, CNAME from TRAVEL WHERE TRAVELDATE BETWEEN ‘2015-12-31’ AND ‘2015-05-01’ ;
4. SELECT * FROM TRAVEL WHERE KM > 120 ORDER BY NOP;
5. COUNT(*) VCODE
2 V01
2 V02
6. DISTINCT VCODE
V01
V02
V03
V04
V05
7. VCODE CNAME VEHICLETYPE
V02 Ravi Anish AC DELUXE BUS
V04 John Malina CAR
8. CNAME KM*PERKM
Sahanubhuti 2700

RAMAKRISHNA ACADEMY 7003793770


2
SQL (Structure Query Language)

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;

Table: School
EXPERIENC
CODE TEACHER SUBJECT DOJ PERIODS
E
1001 RAVI SHANKAR ENGLISH 12/03/2000 24 10
1009 PRIYA RAI PHYSICS 03/09/1998 26 12
1203 LIS ANAND ENGLISH 09/04/2000 27 15
1045 YASHRAJ MATHS 24/08/2000 24 16
1123 GANAN PHYSICS 16/07/1999 28 3
1167 HARISH B CHEMISTRY 19/10/1999 27 5
1215 UMESH PHYSICS 11/05/1998 22 16

Table: ADMIN

CODE GENDER DESIGNATION


1001 MALE VICE PRINCIPAL
1009 FEMALE COORDINATOR
1203 FEMALE COORDINATOR

1045 MALE HOD


1123 MALE SENIOR TEACHER
1167 MALE SENIOR TEACHER
1215 MALE HOD

RAMAKRISHNA ACADEMY 7003793770


3
SQL (Structure Query Language)

ANSWER
1. VICE PRINCIPAL
2. 16
3. UMESH
YASH RAJ
4. MALE
FEMALE

RAMAKRISHNA ACADEMY 7003793770


4
SQL (Structure Query Language)

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

Table: School
TCODE TTYPE PERKM Note:
103 ORDINARY BUS 90  PERKS is Freight Charges per kilometer
105 SUV 40  TTYPE is Transport Vehicle Type
104 CAR 20
103 ORDINARY BUS 90 Note:
101 VOLVO BUS 160  NO is Driver Number
102 AC DELUXE BUS 140  KM is Kilometer travelled
 NOP is number of travelers travelled in vehicle
 TDATE is Trip Date
Table: TRIP`
NO NAME TDATE KM TCODE NOP
11 Tanish Khan 2015-12-13 200 101 32
13 Danish Sahai 2016-06-21 100 103 45
15 Ram Kumar 2016-02-23 350 102 42
12 Fen Shen 2016-01-13 90 102 40
17 Aan Kumar 2015-02-10 75 104 2
14 Veena 2016-06-28 80 105 4
16 Rajpal Kirti 2016-06-06 200 101 25

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′;

RAMAKRISHNA ACADEMY 7003793770


5
SQL (Structure Query Language)

ANSWER

1. SELECT NO, NAME, TDATE FROM TRIP ORDER BY NO;

SELECT NAME FROM TRIP


2. WHERE TCODE = 101 OR TCODE = 103;

SELECT NO AND NAME FROM TRIP


3. WHERE ‘2015-02-10’ < TDATE < ‘2015-04-01’;

SELECT NO, NAME, TDATE, KM, TCODE FROM TRIP


4. 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

TO DISPAY THE NAME AND CODE OF THOSE TRANS PORTERS, WHO HAVE
7. TRAVELLED MORE THAN 90 KMS.

TO DISPLAY THE NAME AND EXPENDITARE OF A TRANSPORTER WHO HAVE


8. TCODE AS 105.

RAMAKRISHNA ACADEMY 7003793770


6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy