我正在测试查询以确保它们返回正确的结果。但是我注意到我弄错了时间。我的时间戳之一是
2013-02-07 07:26:04
我减去:
2013-02-07 07:18:23
从第一个时间戳
这给了我十二分钟左右的差异。现在我不是数学天才,但我什至可以说 18 - 12 = 6... 不是 12... 所以我知道查询有问题。所以我删除了 SEC_TO_TIME 它给了我正确的时间差异:
+------------+-----------+--------------+----------------+--------+----------+
| session_id | anum | first | last | why | time |
+------------+-----------+--------------+----------------+--------+----------+
| 220 | B00000000 | Testing | thisout | Other | 00:07:41 |
+------------+-----------+--------------+----------------+--------+----------+
This is my query now :
SELECT
session.session_id,
session.anum,
student.first,
student.last,
session.why,
(TIMEDIFF(t.fin, session.signintime)) AS time
FROM session
INNER JOIN student
ON session.anum = student.anum
LEFT JOIN (SELECT support.session_id, MAX(support.finishtime) AS fin FROM support GROUP BY support.session_id) AS t
ON t.session_id = session.session_id
WHERE session.status = 3
当我在 TIMEDIFF 之前添加 SEC_TO_TIME 时,问题就来了。
为什么会这样?
现在只是向你们展示 SEC_TO_TIME 的查询结果:
+------------+-----------+--------------+----------------+--------+----------+
| session_id | anum | first | last | why | time |
+------------+-----------+--------------+----------------+--------+----------+
| 220 | B00000000 | Testing | thisout | Other | 00:12:21 |
+------------+-----------+--------------+----------------+--------+----------+
2 rows in set (0.00 sec)
任何解释都会很可爱。