日期:2014-05-18  浏览次数:20386 次

请,各位高手大哥们,帮帮小弟解决个SQL查询问题。
这个问题和我之前提的问题好像一样,不过个人觉得比上个题升级了一点。

表:   A表                                         b表
          a         b         c                         x         y           z  
          1         2         3                         4         5           6

内容:显示(视图)                 c表
                                                    f1       f2         f3           f4
                                                    1         2           3             Null
                                                    4         5           Null       6
无限感谢!

------解决方案--------------------

create view c
as
select a as f1,b as f2,c as f3,null as f4 from A
union all
select x,y,null,z
go
------解决方案--------------------

Create View C
As
Select a As f1, b As f2 , c As f3, Null As f4 From A
Union All
Select x, y, Null, z From B
GO
------解决方案--------------------
create table A(a int,b int,c int)
insert into A select 1,2,3

create table B(x int,y int,z int)
insert into B select 4,5,6
go

create view c
as
select a as f1,b as f2,c as f3,null as f4 from A
union all
select x,y,null,z from B
go

select * from c
go

drop view c
drop table A,B
go

------解决方案--------------------
create table A(a int,b int,c int)
insert into A select 1,2,3

create table B(x int,y int,z int)
insert into B select 4,5,6
go

create view c
as
select a as f1,b as f2,c as f3,null as f4 from A
union all
select x,y,null,z from B
go

select * from c
/*
f1 f2 f3 f4
----------- ----------- ----------- -----------
1 2 3 NULL
4 5 NULL 6
*/
go

drop view c
drop table A,B
go

------解决方案--------------------
create view v
as
select a as f1,b as f2,c as f3,null as f4 from A
union all
select x,y,null,z from B
go
------解决方案--------------------
吧鱼的代码抄过来下

Create View C