当前位置: 技术问答>linux和unix
mysql order by 失效了?
来源: 互联网 发布时间:2017-03-17
本文导语: 我的表是地址和ip组成,都是char型的,这个表是我用其他表做成的,我想用order by 查看地址多少分布,我用的语句是 select host,ip from a order by host desc limit 200; 可是出来的结果却不是按从多到少的顺序来的,...
我的表是地址和ip组成,都是char型的,这个表是我用其他表做成的,我想用order by 查看地址多少分布,我用的语句是
select host,ip from a order by host desc limit 200;
可是出来的结果却不是按从多到少的顺序来的,很是混乱,我就搞不清楚了这是怎么了?怎么失效了吗,可是有些其他表没问题啊?
如图
+-------------------------------------+------------------+
| host | ip |
+-------------------------------------+------------------+
| http://yximg.mop.com | 60.29.242.112
|
| http://y3.ifengimg.com | 121.194.1.117
|
| http://y3.ifengimg.com | 58.205.224.142
|
| http://y3.ifengimg.com | 113.57.252.238
|
| http://y3.ifengimg.com | 59.175.130.246
|
| http://y3.ifengimg.com | 59.175.130.53
|
| http://y2.ifengimg.com | 59.175.130.106
|
| http://y0.ifengimg.com | 59.173.15.238
|
| http://y0.ifengimg.com | 59.175.131.159
|
| http://y0.ifengimg.com | 59.175.131.238
|
| http://y0.ifengimg.com | 219.139.25.81
|
select host,ip from a order by host desc limit 200;
可是出来的结果却不是按从多到少的顺序来的,很是混乱,我就搞不清楚了这是怎么了?怎么失效了吗,可是有些其他表没问题啊?
如图
+-------------------------------------+------------------+
| host | ip |
+-------------------------------------+------------------+
| http://yximg.mop.com | 60.29.242.112
|
| http://y3.ifengimg.com | 121.194.1.117
|
| http://y3.ifengimg.com | 58.205.224.142
|
| http://y3.ifengimg.com | 113.57.252.238
|
| http://y3.ifengimg.com | 59.175.130.246
|
| http://y3.ifengimg.com | 59.175.130.53
|
| http://y2.ifengimg.com | 59.175.130.106
|
| http://y0.ifengimg.com | 59.173.15.238
|
| http://y0.ifengimg.com | 59.175.131.159
|
| http://y0.ifengimg.com | 59.175.131.238
|
| http://y0.ifengimg.com | 219.139.25.81
|
|
从多到少排序,在sql中对host进行分组统计数量,然后按数排序。
SELECT host, count(ip) n FROM table1 GROUP BY(host) ORDER BY n desc
SELECT host, count(ip) n FROM table1 GROUP BY(host) ORDER BY n desc