mysql - 结合SUB_DATE和TIMEDIFF在mysql中减去1小时

标签 mysql date

我在使用 timediffDATE_SUB 时遇到问题。这是我的 MYSQL 查询:

SELECT id, clock_user_id, clock_date,

(Select clock_time from aura_clock where aura_clock.clock_type = 'Start' and  
 aura_clock.clock_date = t1.clock_date) as start, (Select clock_time 
 from aura_clock where aura_clock.clock_type = 'Stop' 
 and aura_clock.clock_date =   
 t1.clock_date) as Stop,

问题从这里开始

TIMEDIFF((select clock_time FROM aura_clock t 
WHERE t.clock_date = t1.clock_date AND t.clock_time > t1.clock_time 
ORDER BY t.clock_time LIMIT 1), MIN(clock_time)) as spent

FROM aura_clock t1 WHERE t1.clock_date >= DATE_SUB(DATE_SUB(CURDATE(), INTERVAL 
WEEKDAY(CURDATE()) DAY),INTERVAL 15 day) 
AND t1.clock_date < DATE_SUB(curdate(),INTERVAL DAYOFWEEK(curdate()) + 6 day)

GROUP BY clock_date

结果是:

enter image description here

现在,我想从使用 DATE_SUB 所花费的时间中减去 1 小时,但它不起作用。

最佳答案

正如mirkobrankovic所写:

((TIMEDIFF((select clock_time FROM aura_clock t 
WHERE t.clock_date = t1.clock_date AND t.clock_time > t1.clock_time 
ORDER BY t.clock_time LIMIT 1), MIN(clock_time))) - INTERVAL 1 HOUR) AS new_spent

应该可以

编辑:

我得到的最好的是以秒为单位的时间: http://sqlfiddle.com/#!2/18160/66/0

很大程度上取决于 MYSQL 版本

关于mysql - 结合SUB_DATE和TIMEDIFF在mysql中减去1小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17857774/

相关文章:

Android GreenDao - 如何比较两个日期字符串?

php - 是否可以触发数据库更改并在 Laravel 中触发事件?

mysql - 我应该如何解析MySQL中的--secure-file-priv?

python - django "in"子句是否要求列表有两个值?

matlab - 两个数据集的交集

oracle 将 DD-MON-YY 转换为 DD/MM/YYYY

date - 昨天日期使用 VBS 代码和批处理文件(格式 : YYYY_MM_DD)

php - 使用 MySql Fetch Array 和 Ajax 创建可点击的链接

mysql - 将大文件(exe、dll、xml)添加到 mysql 数据库中的表单元格中

mysql - 使用 MySQL 检查条件(日期、时间)