Create the Railway schema using the commands
Q1 Create following tables
( a) trainhalts (id varchar(5) seqno integer stcode varchar(10), timein varchar(5) ,timeout varchar(5) primary key (id,seqno) );
This table stores the distances between directly connected stations stcode1 and stcode2.
Assume that this represents a directed track. i.e, for two stations A and B, there will be
an entry corresponding to (A, B, distance) and another for (B,A, distance).
(b) track (stcode1 varchar(5) ,stcode2 varchar(5), distance integer ,
primary key (stcode1,stcode2) );
C) table station (stcode varchar(5), name varchar(20),
primary key (stcode));
(d)table train (id varchar(5) ,name varchar(20), primary key (id) );
Enter following the data from a.sql
1. Find
pairs of stations (station codes) that have a track (direct connection) with
distance less than 20Kms between them.
2. Find the
IDs of all the trains which have a stop at THANE
3. Find the
names of all trains that start at MUMBAI.
4. List all
the stations in order of visit by the train 'CST-AMR_LOCAL'.
5. Find the
name of the trains which have stop at Thane, before the 6th station in the
route of the train.
1.Find pairs of stations (station codes) that have a track (direct connection) with distance less than 20Kms between them.
select stcode1 ,stcode2 from track where distance <20;
2.Find the IDs of all the trains which have a stop at THANE
select id ,stcode from trainhalts where stcode=(select stcode from station wherename='THANE');
3.Find the names of all trains that start at MUMBAI.
select name from train where id in (select id from trainhalts where seqno=0 and stcode=(select stcode from station where name='MUMBAI'));
4.List all the stations in order of visit by the train 'CST-AMR_LOCAL'.
select s.name from station s,train t,trainhalts tr where t.id=tr.id and tr.stcode=s.stcode and t.name='CST-AMR_LOCAL';
5.Find the name of the trains which have stop at Thane, before the 6th station in the route of the train.
select t.name from station s,train t,trainhalts tr where tr.seqno < 6 and tr.stcode = s.stcode and s.name='THANE' and tr.id=t.id;
Comments
Post a Comment