I am trying to put together an SQL query where I can count 3 columns and group by another one.
Here is the table:
id thedate cars bikes planes from stats group by thedate
What I'm trying to do is to get the totals for each day of each cars, bikes and planes.
So I've tried:
SELECT id, thedate, cars, bikes, planes from stats GROUP BY thedate
SELECT id, thedate, count(cars), count(bikes), count(planes) from stats GROUP BY thedate
None of them work.
How can I do this?
答案 0 :(得分:1)
SELECT DATE(thedate), count(cars), count(bikes), count(planes) from stats GROUP BY DATE(thedate)
You should group by date only (without hours and minutes) and shouldn't select an id field.