SQL:数据按多列去重

1.用 group by 按多列分组

  • 可以用 group_concat() 函数把不需要去重列的数据也取出来。
select group_concat(interfaceid), ip, port from interface group by ip, port;

2.用 distinct 按多列去重

  • distinct 可以对多列去重。不能把不需要去重列的数据取出来,且 distinct 必须放在最前面。
select distinct ip, port from interface;

猜你喜欢

转载自blog.csdn.net/name_sakura/article/details/130889925
今日推荐