Pergunta

Is count not a valid aggregation function for row partitions for SQL DB2 on the iSeries?

This query works:

select ROW_NUMBER() over (partition by COL1, COL2 order by COL3 asc)
from MyTable

And this query gives a syntax error:

select COUNT(1) over (partition by COL1, COL2)
from MyTable

The error message is pointing at the parenthesis before the word partition:

[Message SQL0401] Token ( is not a valid token. A partial list of valid tokens is , FROM INTO.

I'm aware I can rewrite the query to avoid the row partition, but I'd like to know why this isn't working.

Foi útil?

Solução

No, COUNT() is not the same type of function as ROW_NUMBER().

If you want the number of rows per (col1,col2) then you could simply use

select COL1, COL2, count(*)
  from MyTable
  group by col1, col2
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top