要求:统计2021-12-07当天的 设备工时,设备称重。工时需转化为小时,表中为秒
SELECT
sum( a.weight ) AS `value`,
sum(a.work_duration)/3600 AS GONSHI,
a.d AS date
FROM
( SELECT *, DATE_FORMAT( datetime, '%Y-%m-%d' ) AS d FROM t_fuel WHERE device_id = 'SY037JCB18128' )
a
WHERE
a.d BETWEEN '2021-12-07'
AND '2021-12-07'
GROUP BY
a.d
踩坑须知:
1、SQL的时间格式传入必须严格 与格式相匹配。如SQL中用 %Y-%m-%d,那对应的只能用 年-月-日,多加 时分秒都会导致查询结果为null