表格:
age
20
21
20
22
现在想 group by age后 替换掉原表格,请问能否做到?谢谢
------解决方案--------------------
----------------------------------------------------------------
-- Author :DBA_HuangZJ(發糞塗牆)
-- Date :2014-07-14 14:26:04
-- Version:
-- Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
-- May 14 2014 18:34:29
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
go
create table [TB]([age] int)
insert [TB]
select 20 union all
select 21 union all
select 20 union all
select 22
--------------开始查询--------------------------
select DISTINCT age INTO #t
from [TB]
TRUNCATE TABLE tb
INSERT INTO TB SELECT * FROM #t
SELECT * FROM TB
----------------结果----------------------------
/*
age
-----------
20
21
22
*/