SQL with codition on calculated value
Posted
by
user619893
on Stack Overflow
See other posts from Stack Overflow
or by user619893
Published on 2011-02-16T15:22:06Z
Indexed on
2011/02/16
15:25 UTC
Read the original article
Hit count: 161
I have a table with products, their amount and their price. I need to select all entries where the average price per article is between a range. My query so far: SELECT productid,AVG(SUM(price)/SUM(amount)) AS avg FROM stock WHERE avg>=$from AND avg<=$to GROUP BY productid If do this, it tells me avg doesnt exist. Also i obviously need to group by because the sum and average need to be per wine
© Stack Overflow or respective owner