将列值相同的放在一起显示

时间:2022-07-18 22:31:45
表有3列
ident src_ip  dst_ip

现在将src_ip和dst_ip相同的放在一起并且ident从小到大显示。表中src_ip和dst_ip相同的不在一起,杂乱无章的。

3 个解决方案

#1


给出具体的数据看看

#2


mysql> select * from table order by src_ip,dst_ip;
mysql> select ident,src_ip,group_concat(dst_ip) from table group by src_ip;
mysql> select ident,group_concat(src_ip),dst_ip from table group by dst_ip;

#3


引用 2 楼 chengchow2001 的回复:
mysql> select * from table order by src_ip,dst_ip;
mysql> select ident,src_ip,group_concat(dst_ip) from table group by src_ip;
mysql> select ident,group_concat(src_ip),dst_ip from table group by dst_ip;


第一个稍微改一下就可以了

#1


给出具体的数据看看

#2


mysql> select * from table order by src_ip,dst_ip;
mysql> select ident,src_ip,group_concat(dst_ip) from table group by src_ip;
mysql> select ident,group_concat(src_ip),dst_ip from table group by dst_ip;

#3


引用 2 楼 chengchow2001 的回复:
mysql> select * from table order by src_ip,dst_ip;
mysql> select ident,src_ip,group_concat(dst_ip) from table group by src_ip;
mysql> select ident,group_concat(src_ip),dst_ip from table group by dst_ip;


第一个稍微改一下就可以了