Tech Neo 创造一个纯粹高质的技术交流平台

求助SQL Sever如何将多个表合并成一个表

我想创建一个视图,把下面的表全部合称到一个表中去,方便我直接进行查询,不在乎效率低下,求助高手帮忙看看该怎么写

请先 登录 后评论

最佳答案 2018-06-08 15:29

create view all_table as
begin
SELECT *
FROM offices o
inner join countries c on c.id = o.countryid
inner join users u on u.officeid = o.id
inner join roles r on r.id = u.roleid
inner join airports a on a.countryid = c.id
inner join routes ro on ro.arrivalairportid = a.id and ro.departureairportid = a.id
inner join schedules s on s.routeid = ro.id
inner join aircrafts ai on ai.id = s.aircraftid
end

请先 登录 后评论

其它 2 个回答

博问用户

看不懂图,就将表这边连接,那边连接,然后就好了

请先 登录 后评论
博问用户

create view v_port(自己命名) as

select *

from office a inner join Users b on  a.ID=b.QliaceID

inner join Roles c on b.RoleID=c.ID

inner join Countries d on a.countryid=d.id

inner join Airports e on e.countryID=d.id

inner join  routcs f on e.id=f.arrayairportID and e.id=DepartureAirportID

inner join  Schcdulcs g on f.id=g.routcID

inner join Aircrafts h on g.AirportID=h.id

可以选择left join (左关联或者右关联) 关键字段有些看不清楚,自己对一对。 

请先 登录 后评论