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