Need help with a query TOP 5 and rest

I need to make a top 5 of canceled contracts in a query, but I also need to bring the rest, because I need to plot the top 5 most canceled contracts and I need to know the rest in a single return.

The top 5 i managed to do, I just can't take advantage of the same query to bring the rest.

WHERE dca.ano = 2021 AND dcm.mes = 8
AND dce.fornecedor IN ["BRADESCO","SulAmérica Saúde","CNU","AMIL","UNIMED-RIO"]
return dce.fornecedor as Fornecedor, count(dce) as forc order by forc desc

How does that limit to just the top 5? I don't see LIMIT 5 anywhere in there.

Are you arbitrarily filtering the top 5 using the IN clause?

Would like to help but need more information.

To use 2 queries, you can use LIMIT 5 for the top 5 (after order by). Then use SKIP 5 for the other query.

To use a single query, return the entire set and split it client side.


1 Like