If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
WITH T (EMP_NO, LAST_NAME, FIRST_NAME, rnum) AS
(SELECT EMPNO, LASTNAME, FIRSTNME, row_number() over(order by LASTNAME) FROM EMPLOYEE WHERE EDLEVEL > 12)
SELECT * FROM T where rnum BETWEEN 5 AND 10
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
I don't know other ways without using nested query.
But, the common table expression can be replaced by a nested table expression, in this case.
WITH T(...) AS (SELECT ... )
SELECT * FROM T where rnum BETWEEN 5 AND 10
is equivalent to
SELECT * FROM (SELECT ... ) AS T(...) where rnum BETWEEN 5 AND 10
I don't know other ways without using nested query.
Except the following self-join which is usually inefficient and not practical.
Code:
SELECT a.empno, a.lastname, a.firstnme
, COUNT(b.lastname) AS rnum
FROM employee a
, employee b
WHERE a.edlevel > 12
AND b.edlevel > 12
AND b.lastname <= a.lastname
GROUP BY
a.empno, a.lastname, a.firstnme
HAVING COUNT(b.lastname) BETWEEN 5 AND 10
ORDER BY
COUNT(b.lastname)
;