AVERAGE Count in 4.1.16

This query works in Mysql but I need it to work in 4.1.16
when I run it I get
1064 check right syntax to use near '(`count`) FROM (SELECT DATE_FORMAT(`date_placed`,'%W %d %M %Y'), COUNT(*)' at line1

SELECT AVG(`count`) from (
SELECT DATE_FORMAT( `date_placed` , '%W %d %M %Y' ) , COUNT( * )  `count`
FROM (
SELECT `date_placed`
FROM `orders`
WHERE  `date_placed` >= Date_Sub(CURDATE(), INTERVAL 1 WEEK)
) AS tmp
GROUP BY DATE_FORMAT( `date_placed` , '%W %d %M %Y' )
) as l

I would like a query to return the average of the order count for the entire week. Also I would like a query that returns the average order count for the week from last year. So  Date_Sub(CURDATE(), INTERVAL 1 WEEK) would be  Date_Sub(CURDATE() **MINUS 365 days**, INTERVAL 1 WEEK)

test data
order_id             date_placed
0076619             2006-03-09 14:46:46
0075994             2006-02-15 21:52:59
0075997             2006-02-16 09:35:14
0076008             2006-02-16 12:21:37

Thanks for any help.
Scott_EdgeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

star_trekCommented:
try this you missed a , after Count(*)
SELECT AVG(`count`) from (
SELECT DATE_FORMAT( `date_placed` , '%W %d %M %Y' ) , COUNT( * ),  `count`
FROM (
SELECT `date_placed`
FROM `orders`
WHERE  `date_placed` >= Date_Sub(CURDATE(), INTERVAL 1 WEEK)
) AS tmp
GROUP BY DATE_FORMAT( `date_placed` , '%W %d %M %Y' )
) as l
0
akshah123Commented:
I have version 4.1.12 and the query seems to work just fine on my machine.  (Except for the 1 week part, which i changed to 7 day.)
0
Scott_EdgeAuthor Commented:
I still get a syntax error near

1 WEEK)
) AS tmp
GROUP BY DATE_FORMAT( `date_placed` , '%W %d %M %Y' )
) as l
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Scott_EdgeAuthor Commented:
akshah123 It seems the week interval was what was the problem.

star_trek unfortunetly the query doesn't work with the comma after COUNT(*) thank you for your help though.


Do you know how I can select for the previous years week?
0
akshah123Commented:
>>Do you know how I can select for the previous years week?

Simple try ..


SELECT AVG(`count`) from (
SELECT DATE_FORMAT( `date_placed` , '%W %d %M %Y' ) , COUNT( * )  `count`
FROM (
SELECT `date_placed`
FROM `orders`
WHERE  `date_placed` >= (CURDATE() - INTERVAL 1 YEAR - INTERVAL 7 DAY)
) AS tmp
GROUP BY DATE_FORMAT( `date_placed` , '%W %d %M %Y' )
) as l
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
star_trekCommented:
SELECT AVG(`count`) from (
SELECT DATE_FORMAT( `date_placed` , '%W %d %M %Y' ) , COUNT( * ),  `count`
FROM (
SELECT `date_placed`
FROM `orders`
WHERE  `date_placed` >= Date_Sub(CURDATE(), INTERVAL 7 DAY)
) AS tmp
GROUP BY DATE_FORMAT( `date_placed` , '%W %d %M %Y' )
) as l
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.