
image.png
Unknown column 'sub_total' in 'having clause'
为啥会不认识这个字段?
因为 having 是对分组,聚合后的数据进行过滤操作,而 sub_total 已经经过聚合操作了
所以需要使用聚合后的别名 total
having 区别于 where 就在于 where 是在分组聚合之前进行过滤(对记录行进行操作)

image.png
Unknown column 'sub_total' in 'having clause'
为啥会不认识这个字段?
因为 having 是对分组,聚合后的数据进行过滤操作,而 sub_total 已经经过聚合操作了
所以需要使用聚合后的别名 total
having 区别于 where 就在于 where 是在分组聚合之前进行过滤(对记录行进行操作)