Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql: Trying to get Average of Counts for the last 10 ten days

Select avg(last_10_count) AS last_10_avg
(Select count(*)
from dim_user
where effective_date ::date > current_date -10
group by effective_date ::date) AS last_10_count

When I just run the inline query, I get the desired result, but when I run the whole query it throws the following error:

ERROR: function avg(record) does not exist
LINE 1: Select avg(last_10_count) AS last_10_avg
HINT: NO function matches the given name and arguement types.
      You might need to add explicit type casts.
************Error***************
ERROR: function avg(record)  does not exit
SQL state: 42883
like image 228
DUnkn0wn1 Avatar asked May 02 '14 14:05

DUnkn0wn1


1 Answers

Try this one

Select avg(last_10_count) AS last_10_avg from 
(Select count(*) as last_10_count
from dim_user
where effective_date::date  > current_date -10
group by effective_date :: date) Z
like image 151
giampi_g Avatar answered Nov 15 '22 20:11

giampi_g