日期:2014-05-18 浏览次数:20682 次
--1 select distinct col from tb --2 select col from tb group by col
select distinct col,col2,col3,col4........from tb
------------------------------Version------------------------------------------
--Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
--
------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
create table [tb]([id] int,[date] datetime)
insert [tb] select rand()*10000,getdate()
go 1000000
select distinct id from tb
/*
(10000 行受影响)
SQL Server 执行时间:
CPU 时间 = 780 毫秒,占用时间 = 634 毫秒。
*/
select id from tb group by id
/*
(10000 行受影响)
SQL Server 执行时间:
CPU 时间 = 796 毫秒,占用时间 = 641 毫秒。
*/
--建立聚集索引
create clustered index idtbID ON tb(id)
select distinct id from tb
/*
(10000 行受影响)
SQL Server 执行时间:
CPU 时间 = 172 毫秒,占用时间 = 1495 毫秒。
*/
select id from tb group by id
/*
(10000 行受影响)
SQL Server 执行时间:
CPU 时间 = 172 毫秒,占用时间 = 1489 毫秒。
*/
------解决方案--------------------
帖子不见了
------解决方案--------------------
我是来学习的