首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求建视图SQL语句,

2012-01-19 
求建视图SQL语句,,-------在线等我想建一视图,A表中有3个字段,id1,id2,aa,B表中两字段id,name,我想建一个

求建视图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

热点排行