Db2 query com between and Partition by

Asked

Viewed 96 times

0

I need a help with this query below, it is not doing what I would like. It makes everything perfect. But when I use the between it returns an error. I would like a help on the query.

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) WHERE V.CONT BETWEEN 0 AND 10

Something like that:

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
  • So I would just like this query above to return me the first 10 values. Using between

  • I believe it’s now translated :)

  • Which error is returning?

  • If without the between it works the want bringing some result why you do not use " v.cont >= 0 and v.cont <= 10"

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.