How to return N most “heavy” requests

We have InfluxDb database with request measurement, it contains url tag and duration field.

I need to select top 5 slowest requests (average). I can write similar sql-query for sql server:

select top 5 url, avg_duration 
select url, avg(duration) avg_duration
FROM @request
group by url
) T
ORDER BY T.avg_duration desc

How to write query like this for InfluxDb?

I found this example …

SELECT * FROM measurement ORDER BY time DESC LIMIT 10

This returns last 10 requests. This is not that I need.