Subquery in the WHERE Clause
Let’s Now Identify all Rows of sample_table where the value in the value column exceeds the average value calculated across all rows.
SELECT * FROM sample_table WHERE value > (SELECT AVG(value) FROM sample_table);
Output:
| id | name | value |
| --- | ---- | ----- |
| 4 | D | 25 |
| 5 | E | 30 |
| 6 | F | 35 |
Explanation: This SQL query retrieves rows from the sample_table where the value column exceeds the average value calculated across all rows. It filters the dataset to highlight entries with values higher than the calculated average.
Show All Rows with an Above-Average Value in SQL
In SQL, finding All Rows of an Above Average Value is simple and is retrieved by the AVG() Function. There are various methods available in SQL that help us to easily find the Average value. In this guide, we will learn about various methods with detailed examples and their output.