SQL | Subqueries exercise | Using sub queries to filter with aggregates

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the course listed below!

Software ==> SQL  (198 exercises)
Version ==> Any version of SQL Server
Topic ==> Subqueries  (5 exercises)
Level ==> Relatively easy
Course ==> Introduction to SQL

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Write a sub query to filter events to show only those which have an event name of longer than average length. You will need the AVG and LEN functions to do this.

Sub query returning filtered events

The top 5 results out of 204 events.

You can run your subquery separately by highlighting it to show that the average EventName length is 26 characters:

Sub Query average length

The advantage of a sub query over typing 26 is that it will stay up to date if the average moves.

 

Optionally save this exercise as More words, more important.sql, and close it down.

This page has 0 threads Add post