日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
sql刪除重復(fù)記錄沒有大小關(guān)系時(shí)重復(fù)值的處理方法

sql 刪除重復(fù)記錄沒有大小關(guān)系時(shí),重復(fù)值將如何處理呢? 下文就將為您介紹sql刪除重復(fù)記錄沒有大小關(guān)系時(shí)重復(fù)值的處理方法,供您參考,希望對您有所啟迪。

創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的任城網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

--> --> (roy)生成

if not object_id(tempdb..#t) is null
    drop table #t
go
create table #t([num] int,[name] nvarchar(1))
insert #t
select 1,na union all
select 1,na union all
select 1,na union all
select 2,nb union all
select 2,nb
go方法1:

if object_id(tempdb..#) is not null
    drop table #
select distinct * into # from #t--排除重復(fù)記錄結(jié)果集生成臨時(shí)表#

truncate table #t--清空表

insert #t select * from #    --把臨時(shí)表#插入到表#t中
--查看結(jié)果
select * from #t

/*
num         name
----------- ----
1           a
2           b

(2 行受影響)#p#
*/

--重新執(zhí)行測試數(shù)據(jù)后用方法2
方法2:

alter table #t add id int identity--新增標(biāo)識(shí)列
go
delete a from  #t a where  exists(select 1 from #t where num=a.num and name=a.name and id>a.id)--只保留一條記錄
go
alter table #t drop column id--刪除標(biāo)識(shí)列--查看結(jié)果
select * from #t

/*
num         name
----------- ----
1           a
2           b

(2 行受影響)

*/

--重新執(zhí)行測試數(shù)據(jù)后用方法3
方法3:

declare roy_cursor cursor local for#p#
select count(1)-1,num,name from #t group by num,name having count(1)>1
declare @con int,@num int,@name nvarchar(1)
open roy_cursor
fetch next from roy_cursor into @con,@num,@name
while @@fetch_status=0
begin
    set rowcount @con;
    delete #t where num=@num and name=@name
    set rowcount 0;
    fetch next from roy_cursor into @con,@num,@name
end
close roy_cursor
deallocate roy_cursor--查看結(jié)果
select * from #t
/*
num         name
----------- ----
1           a
2           b

(2 行受影響)
*/
//利用存儲(chǔ)過程

declare @max integer,@id integer
declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) > 1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_status=0
begin
select @max = @max -1
set rowcount @max
delete from 表名 where 主字段 = @id
fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0//使用函數(shù)

select distinct * into #tmp from tablename
drop table tablename
select * into tablename from #tmp
drop table #tmp

本文轉(zhuǎn)載自【web優(yōu)化網(wǎng)】新聞中心:http://www.web-youhua.com/html/web-youhua-198601001.html


本文題目:sql刪除重復(fù)記錄沒有大小關(guān)系時(shí)重復(fù)值的處理方法
當(dāng)前網(wǎng)址:http://www.dlmjj.cn/article/cdosjod.html