influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Top N query

Open iamlaokui opened this issue 12 years ago • 8 comments

How about Top N query for time-series? does influxdb support it?

iamlaokui avatar Jan 26 '14 09:01 iamlaokui

What do you mean by Top N ? Did you mean last/first N in a given time range.

jvshahid avatar Jan 27 '14 18:01 jvshahid

Maybe you mean something that could be done like this?

select count(state) from events group by state where time > yesterday

So you'd then get points with the counts for the last day. Then you can sort those values and do another query where you filter based on the ones you want to see like this:

select count(state) from events group by time(1d), state where time > last_week and state in ('NY', 'CO')

So you'd end up getting the two 2 in that case, assuming they were CO and NY.

pauldix avatar Jan 27 '14 18:01 pauldix

What I mean is more like this.

select * from events order by timestamp desc limit n;

iamlaokui avatar Jan 29 '14 05:01 iamlaokui

There is no order by and there are no plans to add it in the future. Everything is indexed by time series, column, and time. However, limit is supported. That query can be issued like this:

select * from events limit n;

pauldix avatar Jan 29 '14 14:01 pauldix

Understood, How about this? InfluxDB may support order_by_timestamp asc / desc. NOT for all columns.

iamlaokui avatar Jan 29 '14 14:01 iamlaokui

It supports order by timestamp. Can also do:

select * from events order asc limit 1

On Wed, Jan 29, 2014 at 9:16 AM, piaoyuankui [email protected]:

Understood, How about this? InfluxDB may support order_by_timestamp asc / desc. NOT for all columns.

Reply to this email directly or view it on GitHubhttps://github.com/influxdb/influxdb/issues/203#issuecomment-33587540 .

pauldix avatar Jan 29 '14 14:01 pauldix

Awesome!

iamlaokui avatar Jan 29 '14 14:01 iamlaokui

I don't think there's anything actionable here. So I'll go ahead and close this issue.

jvshahid avatar Jan 29 '14 17:01 jvshahid