We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Consider the following to Explain your Question =>
SELECT product, SUM(sale) AS "Total sales"
FROM order_details
GROUP BY product;
Because we have listed one column (the product field) in your SELECT statement that is not encapsulated in the SUM function, you must use the GROUP BY clause. The product field must, therefore, be listed in the GROUP BY clause.
Now, Coming back to your question
=> SELECT FLOOR(AVG(POPULATION)) FROM CITY GROUP BY DISTRICT;
All select statements with Aggregate function DO NOT NECESSARILY need GROUP BY clause. Unlike the Eg. above, You are not selecting and other field except the aggregate field i.e. 'Popoulation'.
Group By on 'District' would generate mutiple groups of 'Disrict' as a result set. i.e. =>
Average Population
You are viewing a single comment's thread. Return to all comments →
Consider the following to Explain your Question =>
SELECT product, SUM(sale) AS "Total sales" FROM order_details GROUP BY product;
Because we have listed one column (the product field) in your SELECT statement that is not encapsulated in the SUM function, you must use the GROUP BY clause. The product field must, therefore, be listed in the GROUP BY clause.
Now, Coming back to your question
=> SELECT FLOOR(AVG(POPULATION)) FROM CITY GROUP BY DISTRICT;
All select statements with Aggregate function DO NOT NECESSARILY need GROUP BY clause. Unlike the Eg. above, You are not selecting and other field except the aggregate field i.e. 'Popoulation'.
Group By on 'District' would generate mutiple groups of 'Disrict' as a result set. i.e. =>
300000 201360 197408 185957 142889 530000 120000 116178 160516 137400 145900 120758 42326
94526 1191043 940968 128857 159103 186076 245772 4694000 563662 252386 122753 192389 273140 ......
But what these guys are looking for is rather just a single values. Hence,
SELECT ROUND(AVG(POPULATION)) FROM CITY; --454,250
SELECT FLOOR(AVG(POPULATION)) FROM CITY; --454,250
Both work and are accepted. Hope this answers your question.