寫乙個sql語句把所有不重複的名字列出來

2025-02-15 13:15:04 字數 2292 閱讀 6478

1樓:網友

不知道是個啥表。。。比較表明是person, 名字列是nameselect name, count(name)from person

group by name

這樣就可以了,還知道每個名出現了幾次。

2樓:網友

你好! 很簡單的。

select distinct name

from (nane所在的表名)

就是加乙個distinct (不同的、不重複的)就可以了!

上面的方法也可以。

希望能幫到你,很晚了,睡覺咯!呵呵。

查詢某欄位不重複記錄的sql語句該怎麼寫

3樓:網友

select * from (select 所選欄位,count(1) as 數量 from t group by 所選欄位) t1 where t1.數量=1

4樓:鍾情小香妞

sql語句去重,distict的用法:

select distinct 欄位名 from [表名]

資料庫中查詢一列相同名稱最多的sql語句怎麼寫

5樓:網友

以表 table_a 的 col_a列, 為例,**如下:

select col_a from

select col_a,count(*)as 'cfsl' from table_a group by col_a ) a

where cfsl in

select max(cfsl) from (select col_a,count(*)as 'cfsl' from group by col_a ) b);

1、將相同的名稱分組,統計重複次數為 'cfsl'。

2、用 max 函式 取 cfsl 最大對應的名稱以上方法各資料庫可通用,如果是支援top函式的資料庫 ,第二部可以使用 top,會簡單一些。

6樓:網友

假設tab列為id

select id, max(cnt)

from (select id, count(*)as cnt from tab group by id) t

那麼這個id就是最多的那個。

如果只要id

select id

from (select id, max(cnt)from (select id, count(*)as cnt from tab group by id) t) t1

7樓:僪語海

查詢表中登陸次數最多的使用者。

select top 1 username,count(*)from userlog

group by username

order by count(*)desc

sql查詢乙個表中重複的名字

8樓:斑馬線下老漁夫

總結:兩個意義上的重複記錄,一是完全重複的記錄,也即所有欄位均重複的記錄,二是部分關鍵欄位重複的記錄,比如name欄位重複,而其他欄位不一定重複或都重複可以忽略。

1、(1)對於第一種重複,比較容易解決,使用複製****如下:select distinct * from tablename

2)如果該表需要刪除重複的記錄(重複記錄保留1條),可以按以下方法刪除,複製****如下:

select distinct * into #tmp from tablename

drop table tablename

select * into tablename from #tmp

drop table #tmp

2、假設有重複的欄位為name,address,要求得到這兩個欄位唯一的結果集,複製****如下:

select identity(int,1,1) as autoid, *into #tmp from tablename

select min(autoid) as autoid into #tmp2 from #tmp group by name,autoid

select * from #tmp where autoid in(select autoid from #tmp2)

sql語句的乙個疑問,為什麼重複的語句不能寫乙個別名,重複使用?

9樓:依紅旭

你的意思應該是使用cte,或者是使用表變數或臨時表 來代替重複的語句,你現在這樣寫 你後面的語句 根本讀取不到前面的那個tb

請教SQL語句,請教一個SQL語句

select a.b.from comment a inner join reply b on a.writer b.writer and a.writer 張三 select from select from commentunion select from reply where writer ...

怎麼把SQL多個表關聯合併成一個表

用union all group by。多少id都沒關係吧,除非你說的是有上千個表。select id,sum qty1 qty1,sum qty2 qty2,sum qty3 qty3 select id,qty1,0 qty2,0 qty3 from 表1 union all select id...

重複夢見認識的男人,重複夢見一個認識的男人

夢見一個認識的男人擁抱自己意味著 委託別人辦的事會有好訊息回報。甚至會另外提供給你更有利的資訊。但是相反的,如果有人拜託你幫忙,卻不可輕易承諾,需先衡量自己的能力範圍,否則會使自己吃力不討好。愛情方面不需要特別培養氣氛,你們自然的交談就是最好的感情催化劑。夢見一個認識的男人擁抱自己的吉凶 雖得尊長 ...