db2选择查询与之间和分区

时间:2015-01-19 23:18:06

标签: sql db2 between partition

我需要一些关于此查询的帮助

SELECT UNIDADE, MATRICULA, NOME, CURSO, ESCOLA, DTATU, HRATU, STATUS,ROW_NUMBER() OVER(ORDER BY NOME ) AS CONT FROM (

SELECT * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY MATRICULA ORDER BY DTATU DESC,HRATU DESC) AS RN,
row_number() OVER ( ORDER BY NOME ) AS rid, UNIDADE, MATRICULA, NOME, CURSO, ESCOLA, DTATU, HRATU, STATUS FROM MOV_PROTOCOLO WHERE MATRICULA!='' ) AS t WHERE MATRICULA!=''and RN = 1) as V WHERE V.CONT BETWEEN 0 AND 10

我想在0到10行之间选择此查询!

像这样的东西

PLACE CODE STATUS CONT

001 41309014 OK 1
001 31121810 OK 2
001 41309634 OK 3
001 31414303 OK 4
001 41461487 OK 5
001 41207203 OK 6
001 41444868 OK 7
001 31344046 OK 8
001 41447131 OK 9
001 41083326 OK 10 

1 个答案:

答案 0 :(得分:0)

我猜你的意思是那样的

SELECT UNIDADE, MATRICULA, NOME, CURSO, ESCOLA, DTATU, HRATU, STATUS
FROM (
    SELECT t.*, ROW_NUMBER() OVER (ORDER BY NOME) AS rid
    FROM (
        SELECT ROW_NUMBER() OVER (PARTITION BY MATRICULA ORDER BY DTATU DESC,HRATU DESC) AS RN,
            UNIDADE, MATRICULA, NOME, CURSO, ESCOLA, DTATU, HRATU, STATUS
        FROM MOV_PROTOCOLO
        WHERE MATRICULA!=''
    ) AS t
    WHERE t.RN = 1
) as V
WHERE V.rid BETWEEN 1 AND 10