• English
  • Log inStart now

NRQL: Segment your data into buckets

Using NRQL, you can split your query results into buckets that cover certain ranges using the buckets function.

Create bucketed NRQL query

To return bucketed results, use the FACET buckets() clause in a NRQL query. A bucketing query has this structure:


You can use bucketed NRQL queries with any attribute stored as a numerical value in the New Relic database.

Bucket query example

  1. Create a NRQL statement with a SELECT statement for an attribute; for example, SELECT average(duration).
  2. Add a FACET clause that facets on buckets(). For example buckets(duration, 40, 10). You can also bucket on a different attribute than the one in the SELECT statement. For example, to show the average duration for database calls: buckets(databaseCallCount, 40, 10).

This query computes the average duration for a specific page path across 10 buckets, with an upper limit of 40. All values above our upper limit of 40 are grouped in the last bucket, >=36.0.

SELECT average(duration) FROM PageView WHERE pageUrl LIKE 'http://webportal.telco%' SINCE 1 week ago FACET buckets(duration, 40, 10)

This query returns these results:

Here's an example of a NRQL query with segments broken out into ten buckets. The bottom bucket will include outliers, so you may want to adjust accordingly.

Copyright © 2023 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.