日期:2014-05-17 浏览次数:20753 次
with
tb1 as
(
.....
),
--------------------------
;with cte as(
...
)b
--请问以上是2个不同的东西? 还是同一个东西的不同写法?
如果是2种,他的应用场景是?
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-03-28 21:44:51
-- 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)
--
----------------------------
--------------开始查询--------------------------
--> 测试数据:[b]
if object_id('[b]') is not null drop table [b]
go
create table [b]([ID] int,[喜爱] varchar(4))
insert [b]
select 1,'唱歌' union all
select 1,'跳舞' union all
select 1,'喝酒' union all
select 2,'吃肉' union all
select 2,'弹琴' union all
select 1,'画画'
--------------开始查询--------------------------
;WITH tb1 AS (SELECT * FROM b)
SELECT * FROM tb1
;WITH cte AS (SELECT * FROM b)
SELECT * FROM cte
/*
ID 喜爱
----------- ----
1 唱歌
1 跳舞
1 喝酒
2 吃肉
2 弹琴
1 画画
(6 行受影响)
ID 喜爱
----------- ----
1 唱歌
1 跳舞
1 喝酒
2 吃肉
2 弹琴
1 画画
(6 行受影响)
*/