关键字 'where' 附近的语法不正确。无法理解这个错误

Incorrect syntax near the keyword 'where'. cant understand this error

select SNo 
from Supplier  
Having AVG(Qty) IN (
    Select SNo, AVG(Qty)AS Average 
    from Supplier 
    Group By SNo 
)
where (Qty) >50 AND (Qty) <100;

您可以使用简单的聚合而不使用子查询:

select sno, avg(Qty) AS Average 
from supplier s
where qty > 50 and qty < 100
group by sno;

如果您想要使用聚合值进行过滤,那么您可以这样做:

select sno, avg(Qty) AS Average 
from supplier s
group by sno
having avg(qty) > 50 and avg(qty) < 100;

来自评论:

I Need to Select SNo from tables with average Qty and more than 50 and less than 100

为此,您可以使用聚合和 having 子句:

select sno, avg(qty) avg_qty
from supplier
group by sno
having avg(qty) > 50 and avg(qty) < 100

你的问题有点令人困惑,但我认为是这样的:

select tbaux.SNo from
(Select SNo, AVG(Qty) AS Average from Supplier Group By SNo ) as tbaux
where (tbaux.Qty) >50 AND (tbaux.Qty) <100;