mysql实现多个字段重复内容的查询

sushaoyang 2012-04-25 01:52:47
表结构如下
time sip dip port

2012-04-20 14:50:41 192.168.12.117 192.168.1.100 1173
2012-04-20 14:50:41 192.168.12.117 192.168.1.100 1173
2012-04-20 14:50:41 188.222.61.224 192.168.120.189 23690
2012-04-20 14:50:41 192.168.16.1 192.168.12.117 0
2012-04-20 14:50:41 139.86.96.146 192.168.120.189 23690
2012-04-20 14:50:41 192.168.12.117 192.168.1.100 1173


想要将sip、dip、port三项都相同的按 重复的次数从高到底排序 输出top20

结果应该是这样

2012-04-20 14:50:41 192.168.12.117 192.168.1.100 1173 3次
2012-04-20 14:50:41 188.222.61.224 192.168.120.189 23690 2次
2012-04-20 14:50:41 192.168.16.1 192.168.12.117 0 1次

如何用mysql实现,请大牛指点下?
...全文
144 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sushaoyang 2012-04-25
  • 打赏
  • 举报
回复
哥们V5 多谢
[Quote=引用 5 楼 的回复:]

select time,sip,dip,port,count(*) from tt
group by time,sip,dip,port
order by 5 desc
limit 20;
[/Quote]
WWWWA 2012-04-25
  • 打赏
  • 举报
回复
select time,sip,dip,port,count(*) from tt
group by time,sip,dip,port
order by 5 desc
limit 20;
sushaoyang 2012-04-25
  • 打赏
  • 举报
回复
不行啊,报错

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dstip dstport,count(*) from syn
group by time srcip dstip dstport

[Quote=引用 2 楼 的回复:]

SQL code
select time sip dip port,count(*) from tb
group by time sip dip port
order by 2 desc
limit 20;
[/Quote]
sushaoyang 2012-04-25
  • 打赏
  • 举报
回复
看错了
[Quote=引用 1 楼 的回复:]

2012-04-20 14:50:41 188.222.61.224 192.168.120.189 23690 2次:
为什么有2次
[/Quote]
rucypli 2012-04-25
  • 打赏
  • 举报
回复
select  time sip dip port,count(*) from tb
group by time sip dip port
order by 2 desc
limit 20;
WWWWA 2012-04-25
  • 打赏
  • 举报
回复
2012-04-20 14:50:41 188.222.61.224 192.168.120.189 23690 2次:
为什么有2次

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧