日期:2014-05-17 浏览次数:20637 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-11-26 11:12:33
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[Employee]
if object_id('[Employee]') is not null drop table [Employee]
go
create table [Employee]([Emp_id] int,[Emp_name] varchar(4))
insert [Employee]
select 1,'张三' union all
select 2,'李四' union all
select 3,'王武'
--> 测试数据:[Application]
if object_id('[Application]') is not null drop table [Application]
go
create table [Application]([apl_id] int,[apl_user] int,[apl_checker] int)
insert [Application]
select 10001,1,3 union all
select 10002,2,3
--------------开始查询--------------------------
select a.apl_id,e.emp_name,c.emp_name
from [Application] a left join Employee e on a.apl_user=e.emp_id
left join employee c on a.apl_checker=c.emp_id
----------------结果----------------------------
/*
(2 row(s) affected)
apl_id emp_name emp_name
----------- -------- --------
10001 张三 王武
10002 李四 王武
*/