How to return N most “heavy” requests

influxdb
influxql

#1

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 
FROM (
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?


#2

I found this example …

SELECT * FROM measurement ORDER BY time DESC LIMIT 10


#3

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