• EnglishEspañol日本語한국어Português
  • Log inStart now

Use nested aggregation to make additional computations

With nested aggregation, you can complete a NRQL query, then make additional computations using the results of that query. Nested aggregation provides NRQL capabilities similar to the class of SQL subqueries or subselects where the subquery is in the FROM clause of the outer query.

Tip

This feature is different from our subquery feature, which allows for subqueries in SELECT and WHERE clauses.

Nested aggregation can help you to answer questions like these without building multiple queries:

  • How can I count the requests per minute for my application, then get the maximum requests per minute for the last hour?
  • How can I compute the average CPU usage of all my servers or hosts, and list only the ones with usage over 90%?
  • From all my user sessions, how can I figure out what percentage bounced immediately?

Nested aggregation query structure

Every NRQL query must begin with a SELECT statement or a FROM clause. A nested aggregation query uses both a SELECT statement and a FROM clause and applies them to a whole query or queries contained within parentheses.

A complete and properly formatted nested aggregation query looks something like this:

SELECT function(attribute)
FROM (
SELECT function(attribute)
FROM dataType
WHERE attribute
TIMESERIES integer units
)

A few other details about query and clause behavior:

  • Nested queries can have more than two levels.
  • You can apply both TIMESERIES and FACET to any part of the nested query. They don't have to be identical at all levels.
  • SINCE, UNTIL, and COMPARE WITH clauses apply to the entire query, and you can only use them at the outermost level.

Nested aggregation query examples

Here are some examples of nested queries:

Copyright © 2024 New Relic Inc.

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