0

对于在凌晨 2:00 关闭的企业,日常会计将在此结束。如何编写或简化此查询以汇总时钟顶部实际在 2:00 的每日流量。

    SELECT date( CAST( Time - INTERVAL 2 HOUR AS DATETIME ) ) AS date, 
CAST( (sum( `in_count` ) + sum( `out_count` ) ) /2 AS UNSIGNED) AS count
FROM establishment
LEFT JOIN `device` ON establishment.establishment_ID = device.establishment_ID
LEFT JOIN `device_state` ON device.device_id = device_state.device_ID
WHERE establishment.establishment_ID =1
AND date(CAST( Time - INTERVAL 2 HOUR AS DATETIME ))
BETWEEN '2013-02-01' AND '2013-03-01'
GROUP BY dayofmonth( CAST( Time - INTERVAL 2 HOUR AS DATETIME ))
ORDER BY Time
4

0 回答 0