获得表里名称、类别相同,价格不同的价格平均值的前后10%的数据,SQL语句怎么写啊,表里的名称有很多的

解决方案 »

  1.   

    假设表为sales,name,kind,price依次表示为名称,种类,价格。select *
    from sales a where exists (select 1 from 
    (select name,kind,avg(price) avg_price from sales group by name,kind) b
    where a.name=b.name and a.kind=b.kind and (a.price>=b.avg_price*0.9 or a.price <=b.avg_price*1.1))