数据库排序

查询员工表中薪水从高到低排序的第5~9条记录
============================================================
SELECT *
FROM (SELECT e.*,rownum rn FROM (SELECT * FROM employee ORDER BY sal DESC) e)
WHERE rn>=5 AND rn<=9;

SELECT *
FROM (SELECT E.*, ROWNUM RN
FROM (SELECT * FROM EMPLOYEE ORDER BY SAL DESC) E WHERE ROWNUM<=9 )
WHERE RN >= 5;

--mysql
SELECT * FROM EMPLOYEE ORDER BY SAL DESC LIMIT 4 , 5
该sql语句的意思是,从第几行开始,然后取多少行,MySQL中第一行的下标是0

posted @ 2017-07-29 11:08  我i编程  阅读(143)  评论(0编辑  收藏  举报