mysqlgroupby上午下午和晚上
我的问题是测量时间不是恒定的.因此,使用正则表达式选择一天中的某一天不起作用.
在下面的查询中,我有时每天还会得到2或4甚至更多结果.这是因为基本上两次测量之间的时间为2小时,但这也不是恒定的,因此第二天的测量在同一时间进行.
是否可以按一天的一部分分组?
或者还有什么其他解决方案?
data:id datumTijd ph tbc temperatuur vbc gbc
1 2012-10-03 14:59:19 7.30.08 24.91 0.02 0
1 2012-10-03 16:47:38 7.33.07 22.15 0.12 0
3 2012-10-03 17:03:06 7.31.09 23.23 0.05 0
query:
SELECT N.name, D.datumTijd, ROUND(D.gbc,2), ROUND(D.vbc,2), ROUND(D.tbc,2),ROUND(D.ph,2), ROUND(D.temperatuur,1)
FROM METING.Name N, METING.Data D
Where D.datumTijd BETWEEN ""+maandag+" 00:00:00" AND ""+vrijdag+" 23:59:59"
AND N.id = D.id AND D.datumTijd
AND D.datumTijd REGEXP "0[78]:..:..|1[34]:..:..|2[12]:..:.."";
ORDER BY N.name, D.datumTijd
最佳答案
您可以这样做,将结果分为3个不同的时期.然后,您可以在度量上使用聚合函数(SUM,MIN,MAX).
SELECT DATE(D.datumTijd), CASE WHEN TIME(D.datumTijd) BETWEEN "08:00:00" AND "14:00:00" THEN 1
WHEN TIME(D.datumTijd) BETWEEN "14:00:00" AND "20:00:00" THEN 2
WHEN TIME(D.datumTijd) BETWEEN "20:00:00" AND "24:00:00" THEN 3
END as period
...
GROUP BY DATE(D.datumTijd),
CASE WHEN TIME(D.datumTijd) BETWEEN "08:00:00" AND "14:00:00" THEN 1
WHEN TIME(D.datumTijd) BETWEEN "14:00:00" AND "20:00:00" THEN 2
WHEN TIME(D.datumTijd) BETWEEN "20:00:00" AND "24:00:00" THEN 3
END
以上是 mysqlgroupby上午下午和晚上 的全部内容, 来源链接: utcz.com/z/533516.html