这样?
select TN.车次,日期,类别,始发站,终点站,硬座价格*t1.序号-硬座价格*t2.序号 as '硬座价格',count(ticketid)
from TN,stop t1,stop t2,stop,ticket a1
where TN.车次 in
(select 车次 from stop where getdate='1945/8/8' and TN.车次 in
(select a.车次
from stop a,stop b where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 ))
and t1.sname='哈尔滨' and t2.sname='莫斯科'
and t2.车次 in
(select a.车次
from stop a,stop b
where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 )
and t1.车次 in
(select a.车次
from stop a,stop b
where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 )
and t1.车次=TN.车次 and t2.车次 = TN.车次 and a1.车次 =t2.车次
and a1.下车站名称= stop.sname
and stop.序号>t2.序号
group by TN.车次,日期,类别,始发站,终点站,硬座价格*t1.序号-硬座价格*t2.序号
想要的结果为:
车次 日期 类型 始发站 终点站 票价 数量
k-25 1945/8/8 装甲列车 莫斯科 哈尔滨 300 3
T-26 1945/8/8 特慢 莫斯科 哈尔滨 15 3[/quote]
这样?
select TN.车次,日期,类别,始发站,终点站,硬座价格*t1.序号-硬座价格*t2.序号 as '硬座价格',count(ticketid)
from TN,stop t1,stop t2,stop,ticket a1
where TN.车次 in
(select 车次 from stop where getdate='1945/8/8' and TN.车次 in
(select a.车次
from stop a,stop b where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 ))
and t1.sname='哈尔滨' and t2.sname='莫斯科'
and t2.车次 in
(select a.车次
from stop a,stop b
where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 )
and t1.车次 in
(select a.车次
from stop a,stop b
where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 )
and t1.车次=TN.车次 and t2.车次 = TN.车次 and a1.车次 =t2.车次
and a1.下车站名称= stop.sname
and stop.序号>t2.序号
group by TN.车次,日期,类别,始发站,终点站,硬座价格*t1.序号-硬座价格*t2.序号
想要的结果为:
车次 日期 类型 始发站 终点站 票价 数量
k-25 1945/8/8 装甲列车 莫斯科 哈尔滨 300 3
T-26 1945/8/8 特慢 莫斯科 哈尔滨 15 3
这样?
select TN.车次,日期,类别,始发站,终点站,硬座价格*t1.序号-硬座价格*t2.序号 as '硬座价格',count(ticketid)
from TN,stop t1,stop t2,stop,ticket a1
where TN.车次 in
(select 车次 from stop where getdate='1945/8/8' and TN.车次 in
(select a.车次
from stop a,stop b where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 ))
and t1.sname='哈尔滨' and t2.sname='莫斯科'
and t2.车次 in
(select a.车次
from stop a,stop b
where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 )
and t1.车次 in
(select a.车次
from stop a,stop b
where a.车次=b.车次 and a.sname = '哈尔滨' and b.sname = '莫斯科' and a.序号>b.序号 )
and t1.车次=TN.车次 and t2.车次 = TN.车次 and a1.车次 =t2.车次
and a1.下车站名称= stop.sname
and stop.序号>t2.序号
group by TN.车次,日期,类别,始发站,终点站,硬座价格*t1.序号-硬座价格*t2.序号
想要的结果为:
车次 日期 类型 始发站 终点站 票价 数量
k-25 1945/8/8 装甲列车 莫斯科 哈尔滨 300 3
T-26 1945/8/8 特慢 莫斯科 哈尔滨 15 3[/quote]