我有一个名为ch6
的表,它有以下字段:
id, daytime, tout, tloss.. etc.
daytime is DATETIME , tout and tloss are integer
现在,我想检索并列出表格中每个日期tloss
和tout
的总和
date || sum(tout) for certain interval || sum(tloss) for certain interval
我面临一些问题,间隔时间到第二天
例如:
20-2-2014 || (sum of tout from 8:00pm to 8:00am the next day) || (sum of tloss between 8:00pm to 8:00am the next day)
解决方案是什么?请帮忙。
答案 0 :(得分:0)
您可以尝试以下
SELECT daytime , SUM(tout) AS total_tout , SUM(tloss) as total_loss
FROM ch6
WHERE daytime
BETWEEN CURRENT_DATE() + INTERVAL 20 HOUR AND CURRENT_DATE() + INTERVAL 32 HOUR
GROUP BY daytime;