postgresql中distinct on ()的用法

distinct on (),括号里面的内容是要去重的列,括号外面的内容是你要查询展示的列,两者没有关系,你可以根据某些列去重不必将他们查询出来,最后这个举一个例子就是:

//我要查询name和age,根据name和sex去重:
select distinct on (name,sex) name,age from student

猜你喜欢

转载自www.cnblogs.com/levylaw/p/12425203.html