Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
關於sql 語法查詢distinct的問題
有題題目要做
查詢某資料表中的欄位1與欄位2(欄位2不重複),並以欄位1由大到小排序
select 欄位1, distinct 欄位2
from 資料表
order by 欄位1
可是查詢出來一直說 distinct 那邊有錯誤
請問我該怎麼修改呢?
2 Answers
- 1 decade agoFavorite Answer
distinct 是讓你所選取的整筆資料不重複, 所以要放在select 之後
select distinct 欄位1, 欄位2
from 資料表
order by 欄位1
因為是整筆資料不重複, 沒有辦法說允許欄位1重複 欄位2 不重複下面是例子
欄位1 欄位2
A B
A C
B C
A C
結果
A B
A C
B C
Source(s): self - 1 decade ago
Select Distinct fieldA ,(Select fieldC from Source_table where PK=ST.PK) AS fieldB
from Source_table ST where .....
PK=primary key or Search rule