SQL Server查詢語句過濾重復(fù)的數(shù)據(jù)
來源:易賢網(wǎng) 閱讀:4168 次 日期:2014-09-17 15:59:40
溫馨提示:易賢網(wǎng)小編為您整理了“SQL Server查詢語句過濾重復(fù)的數(shù)據(jù)”,方便廣大網(wǎng)友查閱!
 

情況一:表中存在完全重復(fù)的的數(shù)據(jù),即所有字段內(nèi)容都是相同的

create table #

(用戶ID int, 姓名 varchar(10), 年齡 int )

insert into #

select 111, '張三', 26 union all

select 222, '李四', 25 union all

select 333, '王五', 30 union all

select 111, '張三', 26

方法: select distinct * from #

情況2:表中存在部分?jǐn)?shù)據(jù)重復(fù)的字段,即 重復(fù)數(shù)據(jù)中至少有一個(gè)字段不重復(fù)create table #(用戶ID int, 姓名 varchar(10), 年齡 int, 日期 DateTime )insert into #select 111, '張三', 26 2010-02-23 union allselect 222, '李四', 25 2010-03-13 union allselect 333, '王五', 30 2011-03-25 union allselect 111, '張三', 26 2011-07-07方法:--當(dāng)兩條重,取日期大的一條

select * from t a

where not exists (select 1 from t where a.用戶ID=用戶ID a.姓名=姓名 and 日期>a.日期)

更多信息請查看IT技術(shù)專欄

更多信息請查看數(shù)據(jù)庫
易賢網(wǎng)手機(jī)網(wǎng)站地址:SQL Server查詢語句過濾重復(fù)的數(shù)據(jù)
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn)

版權(quán)所有:易賢網(wǎng)