Sql查詢語句過濾重複的資料

2022-07-29 10:45:17 字數 1339 閱讀 6704

情況一:表中存在完全重複的的資料,即所有字段內容都是相同的

create

table

# (使用者id 

int,      姓名   

varchar(10

),   年齡

int

) insert

into

# select

111,           '張三

',        

26union

allselect

222,           '李四

',        

25union

allselect

333,           '王五

',        

30union

allselect

111,           '張三

',        

26方法: select

distinct

*from

#情況2:表中存在部分資料重複的字段,即 重複資料中至少有乙個欄位不重複

create

table

# (使用者id

int, 姓名

varchar(10

), 年齡

int, 日期

datetime

) insert

into

# select

111, '張三

',

262010-02

-23union

allselect

222, '李四

',

252010-03

-13union

allselect

333, '王五

',

302011-03

-25union

allselect

111, '張三

',

262011-07

-07方法:--

當兩條重,取日期大的一條

select

*from

t awhere

notexists

(select

1from

t where

a.使用者id

=使用者id a.姓名

=姓名

and日期

>

a.日期)

暫時總結歡迎補充

Sql查詢語句過濾重複的資料

情況一 表中存在完全重複的的資料,即所有字段內容都是相同的 create table 使用者id int,姓名 varchar 10 年齡 int insert into select 111,張三 26union allselect 222,李四 25union allselect 333,王五 ...

乙個過濾重複資料的sql語句

乙個過濾重複資料的sql語句 資料如下 303 標準類別 tr standard manager 107 巡視記錄類別 tr patrol log 61 巡視記錄類別 tr patrol log 221 檢修型別 tr repair log 121 檢修管理計畫類別 tr repair plan 1...

SQL語句學習5 資料過濾

如果需要通過多個列過濾資料,那麼可使用and操作符給where子句附加條件 select 輸出列名1,輸出列名2 from 表 where 過濾列名1,過濾列名2,上述表示將vend id 1001和prod price 5.99作為資料過濾條件 補充 當每新增乙個過濾條件時,便增加乙個and or...