Satch3000
Satch3000

Reputation: 49384

PHP SQL Count 3 column totals and group by another column

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?

Upvotes: 0

Views: 49

Answers (1)

Vadim  Kharitonov
Vadim Kharitonov

Reputation: 1000

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.

Upvotes: 1

Related Questions