Skip to content
Advertisement

Combining 3 Tables and Finding Average Age in SQL

I need to combine three tables and find the average age after combining the three tables using SQL. The name of the age columns in the three tables are pr16pnk.age, pr16puf.age, and pr16yag.age. I have successfully found the results when the tables are separated, but I am having trouble combining the results. Listed below is the code that I used.

Advertisement

Answer

You can use two levels of aggregation. For the average of averages:

However, what you might really want is the overall average, which would be calculated as:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement