微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mysql – Postgresql:尝试获得过去10天的平均值

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

当我只运行内联查询时,我得到了所需的结果,但是当我运行整个查询时,它会抛出以下错误

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

解决方法:

试试这个吧

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐