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.
Nested aggregation can help you to answer questions like these without building multiple queries:
- Can I count the requests per minute for my application, then get the maximum requests per minute for the last hour?
- Can I compute the average CPU usage of all my servers, and list only the ones with usage over 90%?
- From all my user sessions, can I figure out what percentage bounced immediately?
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 will look something like this:
SELECT function(attribute)FROM (SELECT function(attribute)FROM dataTypeWHERE attributeTIMESERIES integer units)
A few other details about query and clause behavior:
- Nested queries can be more than two levels.
FACETcan be applied to any part of the nested query, and don’t need to be identical at all levels.
COMPARE WITHclauses apply to the entire query and can only be used at the outermost level.
Here are some examples of nested queries.
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.