Vous êtes sur la page 1sur 4

1)Write a Query to display the Information present in the Airline_meal and Airli

ne_Service table.
select * from airline_meal union select * from airlines_services;
+---------+-----------+
| Aircode | meal_code |
+---------+-----------+
| A2
| 13
|
| 12
| 15
|
| 12
| 85
|
| C3
| 1
|
| C3
| 2
|
+---------+-----------+
5 rows in set (0.16 sec)
2)Write a Query to display various airlines which offer the service Child Care.
select a.airline_name from airlines_master a where a.aircode in(select ac.aircod
e from
airlines_services ac where ac.service_code in(select s.service_code from service
s where s.service_name='Child'));
+--------------+
| airline_name |
+--------------+
| King fisher |
+--------------+
1 row in set (0.03 sec)

3)Write a Query to display different meal options available in British Airways.


select m.meal_name from meal m where m.meal_code in(select am.meal_code from air
line_meal
am where am.aircode in(select a.aircode from airlines_master a where a.airline_
name='Britanairw
ays'));
+------------+
| meal_name |
+------------+
| chapathi |
| cooldrinks |
| Rice
|
+------------+
3 rows in set (0.00 sec)
4) Find number of tickets booked for each PNR_no using GROUP BY CLAUSE. Hint: Us
e GROUP BY on PNR_No.?
select pnr_no,count(n0_of_seats) as no_of_seats from reservation group by pnr_no
;
+--------+-------------+
| pnr_no | no_of_seats |
+--------+-------------+
|
123 |
1 |
| 2000 |
1 |
| 2001 |
1 |
| 2010 |
1 |
| 2345 |
1 |
| 3183 |
1 |
+--------+-------------+

5)Write a Query to display the maximum departure time for the flights starting f
rom Delhi along with the aircode.
select aircode,max(Dep_time) from flight where source='Delhi'group by aircode;
+---------+---------------+
| aircode | max(Dep_time) |
+---------+---------------+
| C3
| 3am
|
+---------+---------------+
6)Create an INNER JOIN on tables Airline_Service and Airlines_Master having same
Aircode.
mysql> select * from airlines_services am inner join airlines_master a on am.air
code=a.aircode;
+---------+--------------+---------+--------------+
| Aircode | service_code | Aircode | Airline_Name |
+---------+--------------+---------+--------------+
| C3
| 1
| C3
| King fisher |
| C3
| 2
| C3
| King fisher |
+---------+--------------+---------+--------------+
2 rows in set (0.00 sec)
7)Create a LEFT OUTER JOIN on tables flight_details and flight_days to display c
lass_code,
Fare, Seats from flight_details having same Aircraft_code
select * from flight_details fd left outer join flight_days f on fd.aircraft_cod
e=f.aircr
aft_code;
+---------------+------------+------+-------+---------------+----------+
| Aircraft_code | class_code | fare | seats | Aircraft_code | Day_code |
+---------------+------------+------+-------+---------------+----------+
| IC0F2
| 2
| 3000 | 100 | IC0F2
|
3 |
| IC0F1
| 1
| 5000 |
50 | IC0F1
|
2 |
| AC0F1
| 1
| 1000 | 500 | AC0F1
|
1 |
+---------------+------------+------+-------+---------------+----------+
3 rows in set (0.09 sec)
8)Find the distinct PNR numbers that are present.?
select distinct pnr_no from passenger;
+--------+
| pnr_no |
+--------+
|
123 |
| 2000 |
| 2001 |
| 2010 |
| 2345 |
| 3183 |
+--------+
9)Display the number of days in a week on which the 9W01 flight is available.
select count(day_code) from flight_days fd where fd.aircraft_code in(select f.ai
rcraft_co
de from flight f where f.aircraft_code='9VV01');
+-----------------+
| count(day_code) |
+-----------------+

|
2 |
+-----------------+
1 row in set (0.02 sec)
10)Create a SELF JOIN to display the complete route operated by various Airlines
.
select f.source,f.destiation from flight f join flight fl on f.aircraft_code=fl.
aircraft_
code;
+--------+------------+
| source | destiation |
+--------+------------+
| mumbai | AP
|
| vizag | tirupathi |
| Us
| kerala
|
| Britan | India
|
| hyd
| mumbai
|
| Delhi | Hyd
|
| japan | India
|
+--------+------------+
7 rows in set (0.00 sec)
11)Find the number of tickets booked in each class where the number of seats is
greater than 1.
select class_code,count(n0_of_seats)from reservation group by class_code having
count(n0_
of_seats)>1;
+------------+--------------------+
| class_code | count(n0_of_seats) |
+------------+--------------------+
| 1
|
3 |
+------------+--------------------+
1 row in set (0.00 sec)
12)Write a Query to display aircraft_code, class_code and Fare for each Aircraft
. It must also display the total fare
for all the classes of a particular aircraft.
select aircraft_code,class_code,fare,p.total from flight_details natural join(se
lect airc
raft_code,sum(fare) as total from flight_details group by aircraft_code)as p;
+---------------+------------+------+-------+
| aircraft_code | class_code | fare | total |
+---------------+------------+------+-------+
| AC0F1
| 1
| 1000 | 1000 |
| IC0F1
| 1
| 5000 | 5000 |
| IC0F2
| 2
| 3000 | 3000 |
+---------------+------------+------+-------+
13)Find the total number of cancelled seats.?
select count(status) from reservation where status='n0';
+---------------+
| count(status) |
+---------------+
|
1 |
+---------------+

1 row in set (0.00 sec)


14)Write a Query to count the number of tickets for the flights, which fly after
the date '14/3/2001'.
select journey_date,count(n0_of_seats) from reservation group by journey_date ha
ving jour
ney_date>'2001-3-14';
+---------------------+--------------------+
| journey_date
| count(n0_of_seats) |
+---------------------+--------------------+
| 2003-03-18 00:00:00 |
1 |
| 2006-02-12 00:00:00 |
1 |
| 2012-01-05 00:00:00 |
1 |
| 2012-03-05 00:00:00 |
1 |
| 2012-03-13 00:00:00 |
1 |
| 2012-03-17 00:00:00 |
1 |
+---------------------+--------------------+
6 rows in set (0.00 sec)
15)Create an INDEX on column City_code of the City_Master table.
Create INDEX cc on City_master(City_code);
Query OK, 3 rows affected (0.89 sec)
Records: 3 Duplicates: 0 Warnings: 0
16)Write a query to view all the Indexes that have been created.
show index from class_master;
+--------------+------------+----------+--------------+-------------+----------+-------------+---------+--------+------+------------+---------+
| Table
| Non_unique | Key_name | Seq_in_index | Column_name | Collation
| Cardinality |
Sub_part | Packed | Null | Index_type | Comment |
+--------------+------------+----------+--------------+-------------+----------+-------------+---------+--------+------+------------+---------+
| class_master |
0 | PRIMARY |
1 | class_code | A
|
4 |
NULL | NULL |
| BTREE
|
|
+--------------+------------+----------+--------------+-------------+----------+-------------+---------+--------+------+------------+---------+
1 row in set (0.00 sec)
17)Write a query to rename the index created on any table
alter index1 rename to index 2;
18)Write a Query to Drop the Index that you have created.
drop index cc on city_master;
Query OK, 3 rows affected (0.36 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>

Vous aimerez peut-être aussi