日期:2014-05-16 浏览次数:21013 次
mysql> SELECT mobile_num,COUNT(DISTINCT vlr) AS vlrcount FROM alarmdetail GROUP BY mobile_num ORDER BY vlrcount DESC LIMIT 10; +---------------+----------+ | mobile_num | vlrcount | +---------------+----------+ | 8615868157030 | 4 | | 8615888432117 | 4 | | 8615888757011 | 3 | | 8615824157681 | 3 | | 8615888779740 | 3 | | 8613806853520 | 3 | | 8615824459241 | 3 | | 8613566124713 | 3 | | 8615888202117 | 3 | | 8613566169670 | 3 | +---------------+----------+ 10 rows in set (0.00 sec)
mysql> SELECT (SELECT COUNT(1)+1 FROM alarmdetail b WHERE b.id alarmdetail.id ) AS Rank, mobile_num,COUNT(DISTINCT vlr) AS vlrcount -> FROM alarmdetail -> GROUP BY mobile_num -> ORDER BY vlrcount DESC LIMIT 10; +------+---------------+----------+ | Rank | mobile_num | vlrcount | +------+---------------+----------+ | 132 | 8615868157030 | 4 | | 278 | 8615888432117 | 4 | | 264 | 8613566233443 | 3 | | 1147 | 8613567771731 | 3 | | 259 | 8613806853520 | 3 | | 1076 | 8615824145234 | 3 | | 142 | 8615858155622 | 3 | | 1384 | 8615868418510 | 3 | | 361 | 8615869009887 | 3 | | 337 | 8615869174411 | 3 | +------+---------------+----------+ 10 rows in set (0.48 sec)