sql distinct消除重复列陷阱以及如何除掉部分字段相同的记录
如果在test表下面有country和population两个字段,如果其中一个字段如country有重复,而population有重复,如果
使用select distinct country,population from test 是无法去掉这样部分相同的记录的,因为distinct只能加在第一个字段,而且
这样作用的就是distinct(country+population)去重,如果要去掉country中相同的,需要结合group by进行一个嵌套查询。
select * from test where population in(select max(population) from test group by country),这里的max(population)是结合
情况作出的一个选择,依照population进行一个重复列的选择。