Usages ofselect count(*) from ( select row_number() over ( partition by sdn.cnpj order by sdn.id desc ) rank from solicitacao_download_nfe sdn where (cast(? as text) is null or sdn.cnpj = cast(? as text)) and (cast(? as text) is null or substring(sdn.cnpj, 1, 8) = cast(? as text)) and (cast(? as text) is null or sdn.status = cast(? as text)) ) resultado where rank <= ?