在我的表单中,用户提交了许多事件以及与每个事件相关的单独时间。
例如对于阑尾切除术,第一个事件 Event#1 于下午 12:54:33 开始,最后一个事件 Event#12 发生于下午 2:23:04。 因此,对于阑尾切除术,有 12 个事件。
这些事件被放置在一个单独的表中,并带有事件名称的外键(阑尾切除术)。
所以如果我想计算时间量,通过数据库或使用 PHP 会更好。
由于以下原因,我不确定:
PHP:
The time formats are strings and I don't think you can subtract strings
The time formats are like this HH:MM:SS which may be complex to split the strings and reconcatenate them later.
MySQL:
The time formats in the the column are actual times not strings Would have to use mysql joins and then find the total events for that procedure. Which would be complex?
存储过程?
block 引用>我对很多事情还是陌生的,所以我想知道你对这个问题的指导是什么?
最佳答案
使用 SQL:
SELECT procedure_id, SUBTIME(events_max.start, events_min.start) AS duration
FROM procedure
JOIN ( SELECT procedure_id, SELECT MAX(time) AS start FROM procedure_events GROUP BY procedure_id ) AS events_max USING ( procedure_id )
JOIN ( SELECT procedure_id, SELECT MIN(time) AS start FROM procedure_events GROUP BY procedure_id ) AS events_min USING ( procedure_id )
GROUP BY procedure_id
将为您提供过程 ID 和每个过程的持续时间,由第一个事件和最后一个事件开始之间的时间差给出。
关于php - 计算时间长度,通过PHP还是mySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6828915/