gpt4 book ai didi

mysql - 如何解决 MySQL Left WHERE 条件错误?

转载 作者:行者123 更新时间:2023-11-29 05:02:34 24 4
gpt4 key购买 nike

下面的语句给出了没有任何错误的结果,

select 
title as 'unreviewed series',
rating from series
left join reviews
on series.id= reviews.series_id
where rating is null;

但是,下面给出了一个错误:

select title as 'unreviewed series', 
ifnull(avg(rating), null) as 'Average Rating'
from series
left join reviews
on series.id= reviews.series_id
where avg(rating) = null;

mysql给出的错误是在WHERE附近使用了正确的语法。

最佳答案

使用 having 和 group by - where 将不起作用,因为您正在尝试使用聚合函数进行过滤

select title as 'unreviewed series', 
ifnull(avg(rating), null) as 'Average Rating'
from series
left join reviews
on series.id= reviews.series_id
group by title
having avg(rating) is null

关于mysql - 如何解决 MySQL Left WHERE 条件错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55142029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com