如何计算用户在指定日期内缺席的总天数?
这是我认为它如何运作的基本思路,但我不能让整个部分发挥作用。
SELECT total(from - until) FROM absences WHERE absences.user_id = 123
AND absence_date_until <= '1999-12-01' AND absence_date_from >=
'2000-12-01'
CREATE TABLE IF NOT EXISTS `absences` (
`absence_id` int(10) NOT NULL AUTO_INCREMENT,
`absence_created` datetime DEFAULT NULL,
`absence_date_from` datetime DEFAULT NULL,
`absence_date_until` datetime DEFAULT NULL,
`absence_status` enum('PENDING','APPROVED') NOT NULL,
`user_id` int(6) NOT NULL,
PRIMARY KEY (`absence_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
答案 0 :(得分:1)
SELECT SUM(datediff(until, from) + 1) total_absences
FROM absences
WHERE absences.user_id = 123
AND absence_date_until <= '1999-12-01'
AND absence_date_from >= '2000-12-01'
答案 1 :(得分:0)
在mysql中选择datediff()
SELECT datediff(absence_date_from- absence_date_until)
FROM absences WHERE absences.user_id = 123
AND absence_date_until <= '1999-12-01'
AND absence_date_from >= '2000-12-01'