这里分享一下如何给mysql 表加入rownum!对mysql的学习会有帮助!
SELECT @rownum := @rownum +1 nowef,p.*
from emp p,
(select @rownum := 0) e
ORDER BY p.empno DESC;
+-------+-------+--------+-----------+------+------------+---------+---------+--------+
| nowef | EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | deptno |
+-------+-------+--------+-----------+------+------------+---------+---------+--------+
| 1 | 7369 | SMITH | CLERK | 7902 | 1980-10-10 | 800.00 | NULL | 20 |
| 2 | 7499 | ALLEN | SALESMAN | 7698 | 1981-10-10 | 1600.00 | 300.00 | 30 |
| 3 | 7521 | WARD | SALESMAN | 7698 | 1981-10-10 | 1250.00 | 500.00 | 30 |
| 4 | 7566 | JONES | MANAGER | 7839 | 1981-10-10 | 2975.00 | NULL | 20 |
| 5 | 7654 | MARTIN | SALESMAN | 7698 | 1981-10-10 | 1250.00 | 1400.00 | 30 |
| 6 | 7698 | BLAKE | MANAGER | 7839 | 1981-10-10 | 2850.00 | NULL | 30 |
| 7 | 7782 | CLARK | MANAGER | 7839 | 1981-10-10 | 2450.00 | NULL | 10 |
| 8 | 7788 | SCOTT | ANALYST | 7566 | 1987-10-10 | 3000.00 | NULL | 20 |
| 9 | 7839 | KING | PRESIDENT | NULL | 1981-10-10 | 5000.00 | NULL | 10 |
| 10 | 7844 | TURNER | SALESMAN | 7698 | 1981-10-10 | 1500.00 | 0.00 | 30 |
| 11 | 7876 | ADAMS | CLERK | 7788 | 1987-10-10 | 1100.00 | NULL | 20 |
| 12 | 7900 | JAMES | CLERK | 7698 | 1981-10-10 | 950.00 | NULL | 30 |
| 13 | 7902 | FORD | ANALYST | 7566 | 1981-10-10 | 3000.00 | NULL | 20 |
| 14 | 7934 | MILLER | CLERK | 7782 | 1982-10-10 | 1300.00 | NULL | 10 |
+-------+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)