PostgreSQL的DISTINCT關鍵字用於與SELECT語句消除全部重複的記錄,並獲取惟一記錄。有可能的狀況下,當你有多個重複的表中的記錄。雖然取這樣的記錄,它更有意義,獲取惟一的記錄,而不是獲取重複記錄。html
DISTINCT關鍵字消除重複記錄的基本語法以下:mysql
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]sql
一、去重;關鍵字distinct去重功能 在其餘數據庫(oracle、mysql、db二、informix)也有。數據庫
select distinct idfa from nlogs where recvtime>='2015-09-01 00:00:00' and recvtime<'2015-09-03 00:00:00';oracle
二、統計不重複個數函數
select count( distinct( idfa ) ) from nlogs where recvtime>='2015-09-01 00:00:00' and recvtime<'2015-09-03 00:00:00';spa
distinct跟on一塊兒用; 使用DISTINCT ON實現用窗口函數實現的取第一名的功能,這個功能oracle,mysql是沒有的;固然它們有其餘的分析函數能夠替換;頂替;例如row_number, fisrt_values等。orm
獲取每一個idfa最新接收時間:htm
select distinct on (idfa) idfa, recvtime from nlogs where recvtime>='2015-09-01 00:00:00' and recvtime<'2015-09-03 00:00:00';blog
參閱:https://www.cnblogs.com/lottu/p/5553588.html