28

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

4 Answers 4

44
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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you give an example with a where clause inside the avg()? When I try it in SQLite, I get a syntax error. Or does the where clause go outside the avg()? In that case, it would seem ambiguous... filtering the SELECT instead of the AVG().
@LarsH: e.x., SELECT AVG(colname) FROM table WHERE otherCol = 'foo'; If it helps, think of the WHERE clause as being executed first, then the aggregate function AVG() operates on whatever rows remain.
9
select avg(col1) from table;

Comments

7
select avg(column) from table;

Comments

6
SELECT AVG(column) FROM ...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.