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

请,大哥们,帮帮小弟解决个SQL查询有关问题

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

请,各位高手大哥们,帮帮小弟解决个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


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 isnull(f1,0) as f1,isnull(f2,0) as f2,isnull(f3,0) as f3,isnull(f4,0) as f4 from c

[解决办法]
wujxchina() ( ) 信誉:100 2007-08-10 17:10:05 得分: 0


高手们,Null能不能用0来代替。好像Access一样的做法。


谢谢大家的帮助。

--------------------------------------

--如果只是將上面語句中的NULL改為0
Create View C
As
Select a As f1, b As f2 , c As f3, 0 As f4 From A
Union All
Select x, y, 0, z From B
GO

--如果將表中的所有NULL的數據也顯示為0
Create View C
As
Select IsNull(a, 0) As f1, IsNull(b, 0) As f2 , IsNull(c, 0) As f3, 0 As f4 From A
Union All
Select IsNull(x, 0), IsNull(y, 0), 0, IsNull(z, 0) From B
GO

热点排行
Bad Request.