Replies: 1 comment
-
Hello and welcome to SQLPage! This is a good sql question. This can be solved using a common table expression and an UNION: WITH InitialQuery AS (
-- Your complex query goes here
SELECT column1, column2, column3
FROM some_table
WHERE some_condition
)
SELECT -- Return averages first
AVG(column1) AS column1,
AVG(column2) AS column2,
AVG(column3) AS column3
FROM InitialQuery
UNION ALL -- Then return the full results
SELECT * FROM InitialQuery; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
how to add an average new row to a select query?
I have a select query that has 50 rows and I want to add a row on top of all rows named averages to calculate only 4 or the columns averages how do I do it?
Beta Was this translation helpful? Give feedback.
All reactions