1樓:雪00燕
b 正確。
distinct是去掉重複的值。
求助大神,資料庫查詢結果的去重除了distinct關鍵字,還有什麼別的方法沒?
2樓:網友
一般情況下,資料庫去重複有以下那麼三種方法:
第一種:兩條記錄或者多條記錄的每乙個欄位值完全相同,這種情況去重複最簡單,用關鍵字distinct就可以去掉。例:
select distinct * from table
第二種:兩條記錄之間之後只有部分欄位的值是有重複的,但是表存在主鍵或者唯一性id。如果是這種情況的話用distinct是過濾不了的,這就要用到主鍵id的唯一性特點及group by分組。例:
select * from table where id in (select max(id) from table group by [去除重複的欄位名列表,..
第三種:兩條記錄之間之後只有部分欄位的值是有重複的,但是表不存在主鍵或者唯一性id。這種情況可以使用臨時表,講資料複製到臨時表並新增乙個自增長的id,在刪除重複資料之後再刪除臨時表。例:
建立臨時表,並將資料寫入到臨時表。
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
3樓:網友
1. 2個結果進行union 時,也可以去重。
2. group by 也可以去重。
sql語句中distinct是什麼意思
4樓:張百九
在表中,可能會包含重複值。這並不成問題,不過,有時您也許希望僅僅列出不同(distinct)的值。select distinct 表示查詢結果中,去掉了重複的行;distinct表示去掉重複的行。
5樓:教育仁昌
sql資料庫中, distinct表示去掉重複的行,針對包含重複值的資料表,用於返回唯一不同的值。語法是select distinct 列名稱 from 表名稱。如果指定了 select distinct,那麼 order by 子句中的項就必須出現在選擇列表中,否則會出現錯誤。
6樓:己書竹
就是合併重複值啊,就是重複的只顯示乙個,後接列名。
7樓:
distinct 用於返回唯一不同的值。
語法:select distinct 列名稱 from 表名稱。
8樓:網友
選擇唯一的結果集。
例如 表1只有 a1一列。
a1 11345select distinct a1 from 表1結果如下1345
sql不用distinct怎麼去重複?
9樓:網友
不用第distinct就用group byselect distinct name from userselect name from user group by name
這兩個結果是一樣的。
10樓:網友
去除重複的行 distinct與unique功能用法相同 也可以使用group by
11樓:助蘭達水
說這麼複雜?建主索引不也ok嘛!還省時省力!
sql distinct 只顯示乙個欄位問題
12樓:網友
sql 的 distinct ,作用是去除結果集中的重複值。
例1:例2:
13樓:網友
select * from ceshi qualify row_number() over(partition by a1 order by a2 desc)=1
查詢結果是按a1欄位分組,a2欄位降序排列取第一條,不知道是不是你想要的效果。
14樓:我tm不管
select distinct a1,a2 from [ceshi]
select * from [ceshi] where a1 in (select distinct a1 from [ceshi])
這兩個的結果是一樣的啊。
15樓:喵喵汪汪瞄
aa是限制不能重複欄位。bb根據需要用max或者min取得相應的值。
select distinct aa,max(bb)
from table1 group by aa
16樓:網友
顯示a2欄位那你a1欄位肯定要重複的,邏輯上的問題先要考慮清楚。
sql中count(distinct no)的問題
17樓:網友
樓主,你好!我在資料庫中已經幫你測試過了,結果能通過,你看看create table #tb(
id int,zd int
-向臨時表插入演示資料。
insert into #tb values(1,1)insert into #tb values(1,1)insert into #tb values(1,2)insert into #tb values(2,1)insert into #tb values(2,2)--按要求取數,-首先,把int型別的值轉化成字串型別,然後值連線起來;
然後,把重複的值給distinct掉;
最後,再把結果count出來。
select count(distinct (cast(id as char(1)) cast(zd as char(1)))
from #tb
刪除臨時表。
drop table #tb
18樓:網友
distinct 去除重複的,zd 1 2重複,去掉正好是2條,肯定返回2 ,你奧返回4說一下要求,很多能返回4,你不說不能給你判定。
19樓:網友
變通一下就可以了。
select count(distinct convert(nvarchar(20),id)+','+convert(nvarchar(20),zd)) from tb
excel 中 怎麼實現sql中的distinct 功能
20樓:解0人
選中資料範圍->資料->篩選->高階篩選(注意勾選「不選重複記錄」),不過好像只能複製結果在本工作表,然後手動移動到sheet2中。
21樓:網友
選中資料區域,勾選高階篩選對話方塊中的「選擇不重複的記錄」 選項。
sql中distinct的位置
22樓:業餘收藏人
您好,很高興為您解答!
distinct 一般是放在select之後;
sql語句,儲存過程,智慧型更新,SQL 乙個儲存過程中 執行兩個更新操作 怎麼寫
簡單啊,用if判定一下就可以了啊,在update之前先判定name是否為空 if isnull name,update 表 set username username where id id 同等道理,age也一樣的做就可以了。當然,判定條件並列的話,你可以一起判定 如果想使用多條語句的話,有兩種方...
乙個SQL裡的問題,sql語句的問題?
樓主試試這樣的辦法是否可行 先自己定義兩個函式,lower rank s1,s2 和higher rank s1,s2 分別可以返回資料s1和s2中 較小 和 較大 的值 指按某種規則比較,排位靠前和靠後的 然後用。select distinct concat lower rank 列1,列2 hi...
50分,求乙個SQL語句。。。。。
lz你這sql錯的很嚴重啊。先確定這三張表的關係。如果是你可以這樣寫。select category name news id news title count from news leftjoin category on news categoryid category id left join ...