从所选行中获取值并计算其平均值

Fetch values from the selected rows and calculate its average

我正在与 SQL

合作

我有一个名为 review 的 table,其中包含以下行和列

rating | status
-------|----------
5      | 1
5      | 1
4      | 1
2      | 0
5      |-1

我想计算状态为 1 时评分值的平均值,并忽略状态不是 1 的评分行

我该怎么做?

这是我的尝试:

select * from review where status in (
select status from review
group by status having count(*) > 1
)

我能够 select 状态为 1 的行,但是如何从 select 行中获取评分列中的值并计算其平均值?

使用此 queryreturn Average 评级

Select avg(rating) from review WHERE status=1