求sql语句

cjf1009 2005-11-19 03:12:27
表1:事件表
Bstation: int 开始站编号
PNum: int 人数
EStation: int 目的站编号

表2:站名表
ID :int 站编号
stationDes : varchar(10) 站名

要求视图:

开始站名 人数 目的站名
...全文
209 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cjf1009 2005-11-21
  • 打赏
  • 举报
回复
贴错了,结贴
cjf1009 2005-11-21
  • 打赏
  • 举报
回复
select b.Station,c.Envent_desc,a.Pnum,d.Station,a.num,d.price as 目的价,b.price as 本站价,(d.price -b.price)*a.num as 应收票款 from
Test_Envent a
left join Test_Station b on a.Station=b.id
left join Test_Station d on a.AimStation=d.id
left join Test_EnventDesc c on a.Envent=c.Envent
winehero 2005-11-19
  • 打赏
  • 举报
回复
Create View VW_Test
as
select b.stationDes as 开始站名, a.人数 as 人数, c.stationDes as 目的站名
from 事件表 a, 站名表 b, 站名表 c
where a.开始站编号=b.站编号 and
a.目的站编号=c.站编号
QQMagicer 2005-11-19
  • 打赏
  • 举报
回复
select (select stationdes from 站名表 where id = t.Bstation) as 开始站名,
人数,
(select stationdes from 站名表 where id = t.EStation) as 目的站名
from 事件表 t
QQMagicer 2005-11-19
  • 打赏
  • 举报
回复
select (select stationdes from 站名表 where id = t.Bstation) as 开始站名,
人数,
(select stationdes from 站名表 where id = t.EStation) as 目的站名
from 事件表
rivery 2005-11-19
  • 打赏
  • 举报
回复
--try

create view vw_get
as
select 开始站名=(select stationDes from 站名表 where id=a.bstation),
人数=a.PNum,
目的站名=(select stationDes from 站名表 where id=a.EStation)
from 事件表 a
go
zlp321002 2005-11-19
  • 打赏
  • 举报
回复
Create View V_View
as
select
开始站名=(select 站名 from 站名表 where 站编号=A.开始站编号),
人数=A.人数,
目的站名=(select 站名 from 站名表 where 站编号=A.目的站编号),
from
事件表 A
zlp321002 2005-11-19
  • 打赏
  • 举报
回复
--两个表,什么关联??

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧