Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite - how to get average value?

Tags:

sql

I have in my table a column that has values of type FLOAT. How can I get average value of all elements in this column?

like image 994
Ilya Suzdalnitski Avatar asked Apr 28 '09 09:04

Ilya Suzdalnitski


People also ask

How do you find the average value in SQL?

The avg() function has the following syntax: SELECT AVG( column_name ) FROM table_name; The avg() function can be used with the SELECT query for retrieving data from a table.

How do I find the average of each row in SQL?

The average is simply calculated by summing the amounts and divide by the difference between min and max dates for each row.

Can you average in SQL?

SQL AVG function is used to find out the average of a field in various records. You can take average of various records set using GROUP BY clause. Following example will take average all the records related to a single person and you will have average typed pages by every person.

Which aggregate function will find the average?

AVG() function is an aggregate function that calculates the average value of a numerical dataset that returns from the SELECT statement.


2 Answers

select avg( columnname) from table; 

This will average all rows. To average a subset, use a where clause. To average for each group (of something) use a group by clause.

like image 136
tpdi Avatar answered Sep 23 '22 02:09

tpdi


select avg(col1) from table; 
like image 21
Jérôme Avatar answered Sep 23 '22 02:09

Jérôme