简体   繁体   English

PHP SQL Count 3列总计,并按另一列分组

[英]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. 我正在尝试将一个SQL查询放在一起,在其中我可以计算3列并按另一列分组。

Here is the table: 表格如下:

id thedate cars bikes planes from stats group by thedate id thedate汽车由thedates统计组的飞机

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? 我怎样才能做到这一点?

SELECT DATE(thedate), count(cars), count(bikes), count(planes) from stats GROUP BY DATE(thedate)

您应该仅按日期分组(没有小时和分钟),并且不应选择id字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM