sql查詢去掉重覆記錄,SQL查詢,如何去除重複的記錄?

時間 2021-12-29 05:04:27

1樓:

1、利用sql server 2012資源管理器建立資料庫表t_call_info,包含有三個欄位id、cno和cname。

2、建立完畢後,重新整理資料庫book,這時會在表資料夾下生成資料庫表t_call_info。

3、向資料庫表t_call_info插入10條資料。

4、查詢資料庫表資料,這時會看到10條資料記錄。

5、在資料庫滑鼠右鍵建立新查詢,如下圖所示。

6、在生成查詢視窗,編輯動態查詢sql語句,宣告整型tid、字串型sql,然後賦值,最後呼叫引數執行sql語句。

2樓:小舅舅有點帥

以下為去重方法。三個方法。效率1 >2>3 推薦使用第一條

[sql] view plain copy print?

1,select * from stuinfo a where not exists(select 1 from stuinfo where stuname=a.stuname and id2,select a.* from stuinfo a join (select min(id)id,stuname from stuinfo group by stuname) b on a.

stuname=b.stuname and a.id=b.

id3,select * from stuinfo a where id=(select min(id) from stuinfo where stuname=a.stuname)

select * from stuinfo a where not exists(select 1 from stuinfo where stuname=a.stuname and idselect a.* from stuinfo a join (select min(id)id,stuname from stuinfo group by stuname) b on a.

stuname=b.stuname and a.id=b.

idselect * from stuinfo a where id=(select min(id) from stuinfo where stuname=a.stuname)

擴充套件資料

有重複資料主要有一下幾種情況:

1,存在兩條完全相同的紀錄

這是最簡單的一種情況,用關鍵字distinct就可以去掉

example: select distinct * from table(表名) where (條件)

2,存在部分字段相同的紀錄(有主鍵id即唯一鍵)

如果是這種情況的話用distinct是過濾不了的,這就要用到主鍵id的唯一性特點及group by分組

example:

select * from table where id in (select max(id) from table group by [去除重複的欄位名列表,....])

3,沒有唯一鍵id

example:

select identity(int1,1) as id,* into newtable(臨時表) from table

select * from newtable where id in (select max(id) from newtable group by [去除重複的欄位名列表,....])

drop table newtable

sql查詢,如何去除重複的記錄?

3樓:匿名使用者

上面的回答可以,不過我覺得還有更簡單的方法:

select aid, count(distinct uid) from 表名 group by aid

這是sqlserver 的寫法。。。

4樓:樂園小

select distinct 文章aid,使用者uid from table名

5樓:匿名使用者

select * from table a where id in(select max(id) from table bwhere a.uid=b.uid and a.

aid=b.aidgroup by uid)

6樓:匿名使用者

select

aid,

count(distinct uid)

from 表名

group by aid

7樓:匿名使用者

select aid, count(*) from (select distinct aid, uid from 表名) group by aid

8樓:紫燕佳琪

select distinct 。。。。。。

select後加個distinct去掉重複

9樓:雁子

去除重覆記錄(兩行或兩行以上記錄中系列的上的資料都相同),例如emp表中sal欄位就存在相同的記錄。當只查詢emp表的sal欄位時,那麼會出現重覆記錄,那麼想去除重覆記錄,需要使用distinct:

selectdistinctsalfromemp;

sql查詢語句,怎樣查詢重複資料

10樓:小丁創業

1、第一步,開啟資料庫,並建立乙個包含重複資料的新使用者表,見下圖,轉到下面的步驟。

2、第二步,執行完上面的操作之後,輸入如下紅框中的sql語句,然後單擊執行按鈕,以檢視資料庫中使用者表中的重複資料,見下圖,轉到下面的步驟。

3、第三步,執行完上面的操作之後,查詢出了具有重複名稱的資料,見下圖,轉到下面的步驟。

4、第四步,執行完上面的操作之後,可以使用如下語句來去除重複資料,見下圖,轉到下面的步驟。

5、第五步,執行完上面的操作之後,最終刪除了同一類中的重複資料,見下圖。這樣,就解決了這個問題了。

11樓:時間

select id,count(1) as num from table where num>1 group by id

sql 查詢刪除重複行 sql查詢去掉重覆記錄

兩種方法。1 使用distinct關鍵字。2 使用group by關鍵字對出現重複資料的字段進行分組。sql查詢去掉重覆記錄 sql中怎麼刪除兩條重覆記錄並保留一條 10 首先,在表裡加乙個自增長的字段,假設取名為id,這樣每條記錄就有了唯一標識id了,然後,使用 group by 的方式,取出重覆...

sql查詢不重複的記錄,SQL查詢不重複的記錄

select c.from tb as c,select a.productname,a.producttype from select productname,producttype,count productname as cc from tb group by productname,prod...

SQL中提取重覆記錄中時間最近的一條,不重複的直接取出來。時間是datetime型別的

你這不能叫重複資料,處理人 和 環節開始時間 都是不一樣的,想實現你的結果,就要對環節開始時間進行排序,對工單編號 環節名稱進行分組,然後再取 select 工單編號,環節名稱,處理人,環節開始時間 from select row number over partition by 工單編號,環節名稱...

sql裡面如何刪除重複的記錄,SQL裡面如何刪除重複的記錄?

可以用這條語句刪除重覆記錄 delete from select rownumber over partition by 欄位名 from 表名 as e rn where rn 1 sql中如何刪除乙個表中重複的記錄?sql中刪除乙個表中的重覆記錄可以採用如下步驟 1 把a dist表的記錄用di...

SQL如何去重,SQL查詢,如何去除重複的記錄?

1 首先建立乙個臨時表,用於演示sqlserver語法中的去重關鍵字distinct的使用。本文以sqlserver資料庫為例演示,if object id tempdb.tmp1 is not null drop table tmp1 create table tmp1 col1 varchar ...