Average in mysql with date
I am working on Averaging multiple series of data, and I debunked my onset by figuring it out, and I "think" "I am up to the last mistake."
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", dates are already in the database under "date"
I can't get rid of this error, any ideas?
+3
illcrx
source
to share
3 answers
You shouldn't have any space after "CAST":
cast ('2014-05-05' as DATE)
instead
cast ('2014-05-05' as DATE)
By the way, I'm not sure if the mandatory listing of dates when they are already formatted as "yyyy-mm-dd": I'll just write
`column` BETWEEN '2014-02-03' AND '2014-05-05'
+4
nicolas
source
to share
IN mysqlyou can convert string literal to date with function str_to_date
:
SELECT AVG(volume)
FROM _AAPL
WHERE `date` BETWEEN STR_TO_DATE ('2014-02-03', '%Y-%m-%d') AND
STR_TO_DATE ('2014-05-05', '%Y-%m-%d')
+1
Mureinik
source
to share
What are the throws for? It just works like this:
SELECT AVG(volume) FROM _AAPL WHERE date BETWEEN '2014-02-03' AND '2014-05-05';
+1
maszter
source
to share