-
第一步求出个数
-
MySQL [interface_hd_com]> select a.col,COUNT(*) as count,( select count(*) from testtt b where b.col<a.col) as rownum from testtt a group by a.col;
-
+------+-------+--------+
-
| col | count | rownum |
-
+------+-------+--------+
-
| 26 | 1 | 0 |
-
| 35 | 2 | 1 |
-
| 46 | 2 | 3 |
-
| 68 | 2 | 5 |
-
| 92 | 2 | 7 |
-
| 93 | 2 | 9 |
-
+------+-------+--------+
-
6 rows in set (0.00 sec)
第二步:
MySQL [interface_hd_com]> select Nums.a+c.rownum as rank ,col from (select a.col,COUNT(*) as count,( select count(*) from testtt b where b.col<a.col) as rownum from testtt a group by a.col) c,Nums where Nums.a<=count order by col;
+------+------+
| rank | col |
+------+------+
| 1 | 26 |
| 2 | 35 |
| 3 | 35 |
| 4 | 46 |
| 5 | 46 |
| 6 | 68 |
| 7 | 68 |
| 8 | 92 |
| 9 | 92 |
| 10 | 93 |
| 11 | 93 |
+------+------+
11 rows in set (0.01 sec)