摘录自:http://www.cnblogs.com/gaojian/archive/2012/09/05/2671381.html
对于 select distinct on , 可以利用下面的例子来理解:
create table a6(id integer, name varchar(10));
insert into a6 values(1, ' 001');
insert into a6 values(1, '002');
insert into a6 values(2, '003');
insert into a6 values(2, '004');
select distinct on (id) id, name from a6;
id | name
---+--------
1 | 001
2 | 003
(2 rows)