ballouta Posted March 16, 2011 Share Posted March 16, 2011 Hello Kindly help me in this, I want to know what statements are correct in MySQL. A. SELECT state, sum(sales) sum_sales FROM sales WHERE sum_sales > 100 GROUP BY state. B. SELECT state, sum(sales) sum_sales FROM sales HAVING sum(sales) > 100 GROUP BY state. C. SELECT state, sum(sales) sum_sales FROM sales WHERE sum(sales) > 100 GROUP BY state Thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/230763-what-statements-is-correct/ Share on other sites More sharing options...
The Little Guy Posted March 16, 2011 Share Posted March 16, 2011 None, I would do this: SELECT state, sum(sales) as sum_sales FROM sales GROUP BY state HAVING sum_sales > 100 A and B gives an error B The group by comes before the having C and B your doing the sum twice Quote Link to comment https://forums.phpfreaks.com/topic/230763-what-statements-is-correct/#findComment-1188056 Share on other sites More sharing options...
ballouta Posted March 16, 2011 Author Share Posted March 16, 2011 Thank You so much Quote Link to comment https://forums.phpfreaks.com/topic/230763-what-statements-is-correct/#findComment-1188057 Share on other sites More sharing options...
fenway Posted March 17, 2011 Share Posted March 17, 2011 You can't use an aggregate expression in WHERE, only HAVING. Quote Link to comment https://forums.phpfreaks.com/topic/230763-what-statements-is-correct/#findComment-1188758 Share on other sites More sharing options...
ballouta Posted March 18, 2011 Author Share Posted March 18, 2011 Thank You all. Quote Link to comment https://forums.phpfreaks.com/topic/230763-what-statements-is-correct/#findComment-1188959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.