我有一个名为“ counter”的表,该表具有3个字段:
| Field | Type | Null | Key | Default | Extra |
+--------+------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| record | datetime | YES | | NULL | |
| passed | tinyint(1) | YES | | NULL | |
+--------+------------+------+-----+---------+----------------+
我存储在记录中的数据是这样的(传递的是布尔值):
mysql> SELECT record, passed FROM counter;
+---------------------+--------+
| record | passed |
+---------------------+--------+
| 2019-09-19 00:00:00 | 1 |
我想做的是一个查询,该查询总结了按小时和日期分组的传递字段有1次的次数。 例如:
Hour | Date | passed
13:00 2019-09-19 10
执行中:
SELECT HOUR (record), COUNT(*) as passed FROM counter GROUP BY HOUR(record);
我得到那些结果
| HOUR (record) | passed |
+---------------+--------+
| 0 | 67 |
| 13 | 199 |
+---------------+--------+
问题在于13:00之后有记录,根本没有播种。
也为了获得我尝试过的日期:
SELECT DAY(record), COUNT(*), HOUR(record), COUNT(*) as passed FROM counter GROUP BY HOUR(record);
我收到此错误
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'iot.counter.record' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
如何归档所需的结果?
答案 0 :(得分:1)
如果您不介意为日期和时间使用单个字段,则可以在此处使用DATE_FORMAT
:
SELECT
DATE_FORMAT(record, '%Y-%m-%d %H') AS ts,
COUNT(*) AS passed
FROM counter
GROUP BY
DATE_FORMAT(record, '%Y-%m-%d %H');
答案 1 :(得分:0)
请尝试:
batas_mc.addEventListener(Event.ENTER_FRAME, batas);
function batas(e:Event):void
{
removeChild(Batumc);
}