主题:[原创]求助一个查询
create table bus1
(
bid int identity(1,1) primary key,
bname varchar(10) not null
)
create table incept
(
iid int identity(1,1),
iname int references bus1(bid) not null,
istart varchar(30) not null,
iend varchar(30) not null
)
create table line
(
lid int identity(1,1),
lname int references bus1(bid),
station1 varchar(30) not null,
station2 varchar(30) not null
)
insert bus1 (bname) values ('4路')
insert bus1 (bname) values ('5路')
insert bus1 (bname) values ('27路')
insert incept (iname,istart,iend) values (1,'火车站','北门')
insert incept (iname,istart,iend) values (2,'火车站','和平门')
insert incept (iname,istart,iend) values (3,'东门','和平门')
insert line (lname,station1,station2) values (1,'南门','钟楼')
insert line (lname,station1,station2) values (2,'东门','大差市')
select * from bus1
select * from incept
select * from line
select * from bus1 b1,incept b2 where b2.iname=b1.bid
--查询公交车的行驶路线
select (select bname from bus1 where line.lname=bus1.bid) as 'bus',
line.station1,line.station2
from line where line.lname=1
想在这个查询的基础上进行修改,要求是:把bus1的bname列显示出来,还要求把incept表的istart,iend列,line表的station1,station2列一并显示出来,这个查询该怎么写.
(
bid int identity(1,1) primary key,
bname varchar(10) not null
)
create table incept
(
iid int identity(1,1),
iname int references bus1(bid) not null,
istart varchar(30) not null,
iend varchar(30) not null
)
create table line
(
lid int identity(1,1),
lname int references bus1(bid),
station1 varchar(30) not null,
station2 varchar(30) not null
)
insert bus1 (bname) values ('4路')
insert bus1 (bname) values ('5路')
insert bus1 (bname) values ('27路')
insert incept (iname,istart,iend) values (1,'火车站','北门')
insert incept (iname,istart,iend) values (2,'火车站','和平门')
insert incept (iname,istart,iend) values (3,'东门','和平门')
insert line (lname,station1,station2) values (1,'南门','钟楼')
insert line (lname,station1,station2) values (2,'东门','大差市')
select * from bus1
select * from incept
select * from line
select * from bus1 b1,incept b2 where b2.iname=b1.bid
--查询公交车的行驶路线
select (select bname from bus1 where line.lname=bus1.bid) as 'bus',
line.station1,line.station2
from line where line.lname=1
想在这个查询的基础上进行修改,要求是:把bus1的bname列显示出来,还要求把incept表的istart,iend列,line表的station1,station2列一并显示出来,这个查询该怎么写.