Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Average in mysql with date

Tags:

sql

mysql

I am working on Averaging several rows of data and I have been busting my butt figuring it out and I "think" Im down to the last error.

ERROR 1584 (42000): Incorrect parameters in the call to stored function 'cast'

I get this when I run this

select avg(volume) from _AAPL WHERE date between cast('2014-02-03' as date) and cast ('2014-05-05'     as DATE); 

_AAPL is my table, date is my column "date" the dates are already in the database under "date"

I cannot get rid of this error, any ideas?

like image 888
illcrx Avatar asked Nov 28 '25 04:11

illcrx


1 Answers

You should not have any space after "CAST" :

cast('2014-05-05' as DATE)

instead of

cast ('2014-05-05'     as DATE)

By the way i'm not sure it's mandatory to cast dates when they are already formatted like 'yyyy-mm-dd' : i would just write

`column` BETWEEN '2014-02-03' AND '2014-05-05'
like image 91
nicolas Avatar answered Nov 29 '25 19:11

nicolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!