How to get the average from computed columns in postgresql?

Member

by deron , in category: MySQL , 2 months ago

How to get the average from computed columns in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , a month ago

@deron 

You can get the average from computed columns in PostgreSQL by using the aggregate function AVG() in combination with the computed column in your SELECT statement. Here's an example:


Assuming you have a table called example_table with columns column1 and column2, and a computed column computed_column which is the sum of column1 and column2, you can get the average of the computed column like this:

1
2
SELECT AVG(computed_column) AS average_computed_column
FROM example_table;


This will return the average of the values in the computed_column for all records in the example_table.


You can also include additional conditions or group by clauses in your SELECT statement to calculate the average for specific groups of records.