跪求,合并两个表结构相同的SQL语句,分少了点。帮帮忙吧。先谢过了! 在线等
我现在有两个表 表结构一样
结构是: 1.ID EmpID BranchID UpTime Date
2.ID EmpID BranchID DownTime Date
我想这个虚表合成一个表结构如下:
EmpID BranchID UpTime DownTime Date
两个表没有关系 但是有个条件
假如:表1中有 15号员工信息,但表2里面没有15号员工
合并出来的话 是
EMPID BranchID UpTiem DownTiem Date
1 2 8:36 NULL 2007-1-30
这样怎么写SQL语句啊
------解决方案--------------------selec EmpID,BranchID,UpTime,DownTime,Date from
(
select EmpID,BranchID,UpTime, ' ' as DownTime,Date from a1
union all
select EmpID,BranchID, ' ' ,DownTime,Date from b1
)
a
------解决方案----------------------暈, 錯了改改
select EmpID, BranchID, UpTime, DownTiem=null, Date from A
union all
select EmpID, BranchID, UpTime=null, DownTime, Date from B
------解决方案--------------------select
isnull(A.EMPID,B.EMPID),
isnull(A.BranchID,B.BranchID),
UpTiem,DownTiem,
isnull(A.Date,B.Date)
from A full join B on A.EmpID=B.EmpID
------解决方案--------------------select EmpID,BranchID,UpTime,null DownTime Date from A
union all
select EmpID,BranchID,null UpTime,DownTime Date from B