例如下面的查询:
select distinct id, name from user
是将 id 与 name 作为一个组合进行去重操作,如果想要指定按照其中的 id 字段进行去重可以用 group by 与 count 配合使用:
select id, name, count(distinct id) from user group by id, name
例如下面的查询:
select distinct id, name from user
是将 id 与 name 作为一个组合进行去重操作,如果想要指定按照其中的 id 字段进行去重可以用 group by 与 count 配合使用:
select id, name, count(distinct id) from user group by id, name