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

時間 2022-04-11 06:15:36

1樓:鷂式七七

select c.*

from tb as c,

(select a.productname,a.producttype

from (select productname,producttype, count(productname) as cc

from tb

group by productname,producttype)as a

where cc = 1) as b

where c.productname = b.productname and c.producttype = b.producttype

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

2樓:匿名使用者

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

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

這是sqlserver 的寫法。。。

3樓:樂園小

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

4樓:匿名使用者

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

aid=b.aidgroup by uid)

5樓:匿名使用者

select

aid,

count(distinct uid)

from 表名

group by aid

6樓:匿名使用者

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

7樓:紫燕佳琪

select distinct 。。。。。。

select後加個distinct去掉重複

8樓:雁子

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

selectdistinctsalfromemp;

sql 查詢不重覆記錄

9樓:excel小奇

sql查詢不重覆記錄,操作如下:

1、假如要查詢t1表中name欄位中所有的姓名,並去除重複。

2、可以使用如下語句:

select distinct name from t1;

3、其中distinct是去重功能。

10樓:菜園畫畫

那是因為zid相同,這些欄位t_tupian.panelid, t_tupian.title, t_tupian.

uploadtime,t_tupianmingxi.pid as tid, t_tupianmingxi.img 中有不同的,所以不能合併成一行,要麼你只查zid和classid兩個字段,

select distinct(t_tupian.pid) as zid,t_tupian.classid from t_tupian left join t_tupianmingxi on t_tupian.

pid = t_tupianmingxi.classid where t_tupian.panelid=1 and t_tupian.

classid=1 order by uploadtime desc

11樓:匿名使用者

問題是你用了多表查詢,估計你的查詢條件不正確,結果返回迪卡爾積了。

兩個表的key有沒有完全關聯呀!

sql如何查詢兩個表不重複的記錄

12樓:

select a.* from tablea a where a.name not in (select b.name from where tableb b);

用子查詢 簡單 實用,不信你試試。

13樓:匿名使用者

在oracle下最簡單的方法是

select * from tablea

minus

select * from tableb

14樓:

我來回答吧:

select * from tablea where name not in (select name from tableb)

sql 查詢資料表後 在統計某一列資料不重複的數量

15樓:小丁創業

統計第一列不相同的個數的操作方法和步驟如下:

1、首先,建立測試表,**如下圖所示。

2、其次,完成上述步驟後,插入測試資料,**如下圖所示。

3、接著,完成上述步驟後,建立所需臨時表,**如下圖所示。

4、最後,完成上述步驟後,統計每一列不重複的資料量,如下圖所示。這樣,問題就解決了。

sql語句要select某字段不重複的資料應該如何寫?

16樓:

sql語句要select某字段不重複的資料使用distinct關鍵字,例如從 company" 列中僅選取唯一不同的值使用以下sql:

select distinct company from order;

題主的問題b、c欄位資料都相同,可以使用select distinct a,b from table_name 來實現。

擴充套件資料語法:

select distinct 列名稱 from 表名稱

用法注意:

1、distinct 【查詢字段】,必須放在要查詢欄位的開頭,即放在第乙個引數;

2、只能在select 語句中使用,不能在 insert, delete, update 中使用;

3、distinct 表示對後面的所有引數的拼接取 不重複的記錄,即查出的引數拼接每行記錄都是唯一的;

4、不能與all同時使用,預設情況下,查詢時返回的就是所有的結果。

17樓:刺友互

1、右鍵要設定主鍵的表,選擇【設計】,進入表設計視窗。

2、在表設計視窗,選擇一行或者ctrl+滑鼠可以多選行,右鍵選擇【設為主鍵】。

3、如果已經設定有主鍵,則需要先刪除主鍵, alter table 表名 drop constraint 主鍵名稱。

4、表的【索引】選單,右鍵【新建索引】,進入索引建立介面。

5、資料庫唯一索引 - sql語句設定。

6、插入前先判斷記錄是否存在,存在就修改,不存在就新增。

7、插入前先判斷記錄是否存在,不存在就新增,存在就拋棄這條記錄。

18樓:幻翼高達

我們需要準備的材料分別是:電腦、sql查詢器。

1、首先,開啟sql查詢器,連線上要查詢的資料庫表,例如test2表。

2、點選「查詢」按鈕,輸入:select a,b,c from test2 group by a;。

3、點選「執行」按鈕,這時欄位a會以不重複的形式被查詢出所有資料。

19樓:匿名使用者

他們寫的,針對你這組資料可行

但是按照你描述的,這麼寫好像不太好

select a,max(b) from 表名這樣才是你要的a不重複的資料,但是對於欄位b來說,我只取了最大的那個

20樓:赤芬

單獨得到a不重複的資料好辦。

但如果按你的要求想同時包含其他列的資料,因為是關係型資料庫,所以sql的select語句是實現不了的。

21樓:匿名使用者

有資料庫常識的人都知道,,,,,,

你所謂的「不影響到b和c」 能實現麼?????

除非b和c列所有值都一樣。。。。。。(這樣的話,就是網友的推薦答案)再不就是在程式的陣列裡控制了,。。。。。。。。。

兄弟,,,問問題也要考慮可行性 。。。。。

22樓:

select a,max(b) as b,max(c) as c from 表 group by a

23樓:匿名使用者

select distinct(a) from table

24樓:匿名使用者

這個我會啊..

select distinct a,b from 表結果就是

1 2

2 2

3 2

select distinct a from 表結果就是123

25樓:匿名使用者

簡而言之,select distinct a,b from 表名;

26樓:

樓主的意思很明確,可是對資料庫卻不是很了解,按你的意思要得到a列不重複的資料就是下面:

select distinct(a) from table這樣就可以得到a列所有不重複的資料了,但是你還要得到相對應的其他列的資料的時候為了確保重複資料的唯一性,你其他列的資料也必須具有唯一性,如最大(max),最小(min)數量(count)等,所以你的列子可以如下寫:

select distinct(a),min(b),max(c) from table

樓主試了我的沒有,那個網友推薦答案明顯是錯的!

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

1 利用sql server 2012資源管理器建立資料庫表t call info,包含有三個欄位id cno和cname。2 建立完畢後,重新整理資料庫book,這時會在表資料夾下生成資料庫表t call info。3 向資料庫表t call info插入10條資料。4 查詢資料庫表資料,這時會看...

求sql顯示查詢不重複資料命令,「sql」怎麼查詢不重複資料?

必須有唯一標識列才能過濾重複,下面給你個思路 生成唯一id列 select id identity 1,1 bianhao name jiage chandi shuliang into tmp tb from 表1 查詢顯示name不重複的所有資料 select from tmp tb t1 wh...

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

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

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

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

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

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