求建视图SQL语句,,-------在线等
我想建一视图,A表中有3个字段,id1,id2,aa,B表中两字段id,name,我想建一个视图,包含A表中的aa,name1(id1=id),name2(id2=id),请问如何写SQL语句?
------解决方案------------------------是这样麽
create view v1
as
select aa,name1=(select [name] from B表 where a.id1=id),name2=(select [name] from B表 where a.id2=id)
from A表
------解决方案--------------------select a.aa,b.name1,c.name2 from A表 a,B表 b,B表 where a.id2=b.id and a.id1=c.id
------解决方案--------------------select aa,name1=(select [name] from B表 where a.id1=id),name2=(select [name] from B表 where a.id2=id)
from A表
------解决方案--------------------create view v1
AS
select A.aa,B1.name as name1,B2.name as name2
from A
left join B B1 on A.id1=B1.id
left join B B2 on A.id2=B2.id
------解决方案--------------------CREATE VIEW view_a (aa,name1,name2)
AS
SELECT aa,b.name,c.name
FROM (a LEFT OUTER JOIN b
ON a.id1=b.id) LEFT OUTER JOIN b AS c
ON a.id2=c.id