我创建了2个视图,A和B
A:
time quantity1
2014/07/17 5
2014/07/18 6
B:
time quantity2
2014/07/17 7
现在我创建第三张视图,合并A和B为C,效果如下
C:
time quantity1 quantity2
2014/07/17 5 7
2014/07/18 6 NULL(或0)
如果 time字段内容一样的话,我可以做到,但是如果内容不一样我就做不到C那样的格式
用左连接,内连接就显示17号的,用右连接,全连接不显示time字段的18号,
有高手帮帮我吗
------解决方案--------------------
if object_id('[A]') is not null drop table [A]
create table A ( time datetime,quantity1 varchar(20))
go
insert into A
select '2014/07/17','5' union all
select'2014/07/18','6'
go
if object_id('[B]') is not null drop table [B]
create table B ( time datetime,quantity2 varchar(20))
insert into B
select'2014/07/17','7'
go
select A.time,A.quantity1,Isnull(B.quantity2,0)as [quantity2] from A left join B on A.time=B.time
--time quantity1 quantity2
--2014-07-17 00:00:00.000 5 7
--2014-07-18 00:00:00.000 6 0