日期:2014-05-16 浏览次数:20710 次
IF exists(SELECT NAME FROM sys.objects AS o WHERE NAME = 'test')
DROP TABLE test
GO
CREATE TABLE test(id INT IDENTITY(1,1) , fid INT , NAME NVARCHAR(3))
GO
INSERT INTO test
SELECT 0 , N'四川省' union all
SELECT 1 , N'成都市' union all
SELECT 2 , N'青羊区' union all
SELECT 2 , N'金牛区'
;WITH client(id ,shengid , shiid , quid , company) AS (
SELECT 1,1,2,4,N'中国电信公司')
--执行查询
SELECT a.id, c.name ,d.name ,e.name , company FROM client AS a
INNER JOIN test AS c ON a.shengid = c.id
INNER JOIN test AS d ON a.shiid = d.id
INNER JOIN test AS e ON a.quid = e.id
--结果
id name name name company
----------- ---- ---- ---- -------
1 四川省 成都市 金牛区 中国电信公司
(1 row(s) affected)