日期:2014-05-17 浏览次数:20411 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-03-07 22:15:26
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)
-- Jun 17 2011 00:57:23
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------
--> 测试数据:[user]
if object_id('[user]') is not null drop table [user]
go
create table [user]([userID] int,[userName] varchar(1))
insert [user]
select 1,'a' union all
select 2,'b' union all
select 3,'c' union all
select 4,'d' union all
select 5,'e'
--> 测试数据:[work]
if object_id('[work]') is not null drop table [work]
go
create table [work]([oid] int,[cid] int,[mid] int,[intime] datetime)
insert [work]
select 1,2,3,'2013-1-1' union all
select 2,3,4,'2013-1-1' union all
select 4,5,2,'2013-1-1'
--------------开始查询--------------------------
select b.username,c.username,d.username,a.intime from [work] a INNER JOIN [user]b ON a.oid=b.userid
INNER JOIN [user] c ON a.oid=c.userid
INNER JOIN [user] d ON a.oid=d.userid
--------------开始查询--------------------------
----------------结果----------------------------
/*
username username username intime
-------- -------- -------- -----------------------
a a a 2013-01-01 00:00:00.000
b b b 2013-01-01 00:00:00.000
d d d 2013-01-