ROW_NUMBER () OVER () MYSQL

1

Looking at the MySql documentation about row_number() over() I see what can be done, I'm copying exactly the same example adapting it to the database I work with but it gives the following error

  

"(" is not valid at this position, expecting: EOF, ';'

I leave the selection for you to see it. Thanks in advance.

select e.esap_codigo, e.esap_iden,
    ROW_NUMBER() over(partition by e.esap_codigo order by e.esap_codigo, e.esap_iden) as num    
from esap_hco_estados_aparatos e;
    
asked by Oscar Marés Barrera 10.10.2018 в 09:56
source

1 answer

1

I just tried this and it works, I would also like to know if it is possible to overload,

SET @row_number:=0;
SET @db_names:='';
SELECT @row_number:=CASE 
    WHEN @db_names=esap_codigo THEN @row_number+1 ELSE 1 END AS row_number,@db_names:=esap_codigo AS num,
    e.esap_codigo,e.esap_estado, e.esap_fecha, e.esap_destinatario, e.esap_tipo_destino, e.esap_proveedor, e.esap_user_alta 
FROM esap_hco_estados_aparatos e where year(esap_fecha)=2018;
    
answered by 10.10.2018 в 11:25