This query puzzled me ... I was looking for web work in a day, and I tried a lot of things.
I want to get avg the number of orders for each day of the week from my db. I can pull the total number # with COUNT just fine. But I just can't figure out how to get AVG from COUNT on GROUP BY. I tried subqueries ... functions ... everything ... nothing works ... maybe someone can throw me a bone.
Here is the query that I started with below. I know that AVG (COUNT (*)) will not work, but I will leave it because it shows what I want to do.
SELECT
AVG(COUNT(*)) AS avgorders,
SUM(total) AS ordertotal,
DAYNAME(STR_TO_DATE(order_time,'%m/%d/%Y %H:%i')) AS day
FROM data
GROUP BY day
ORDER BY DAYOFWEEK(STR_TO_DATE(order_time,'%m/%d/%Y %H:%i')) ASC
source
share