How to get the average from computed columns in postgresql?

Member

by deron , in category: MySQL , 7 months ago

How to get the average from computed columns in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 7 months 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.

Related Threads:

How to get unique values from 2 columns in postgresql?
How to declare pre-computed columns on mysql?
How to get computed property data in method in vue.js?
How to add columns to auth_user in django postgresql?
How to get the average time in laravel?
How to get average speed ping in python?