这是我的 Mysql 查询
SELECT COUNT(*) CallCnt,ANBCnt, t2.Duration,(ANB) Number,
((DATE_SUB('2012-12-10 05:22:30',
INTERVAL (SELECT CONCAT(''',t2.Duration:0,''')) MINUTE_SECOND))) Mintime,
('2012-12-10 05:22:30') Maxtime,
(1) TYPE,
(t1.CallTypeId)
FROM cdr_temp1_check t1
INNER JOIN cdr_temp1_check_details t2
ON t1.CallTypeId=t2.CallTypeId
WHERE TimeStamp1 >= DATE_SUB('2012-12-10 05:22:30',
INTERVAL (SELECT CONCAT(''',t2.Duration:0,''')) MINUTE_SECOND)
AND TimeStamp1<='2012-12-10 05:22:30'
GROUP BY ANB
HAVING COUNT(*) > ANBCnt
返回的结果是
CallCnt ANBCnt Duration Number Mintime Maxtime TYPE CallTypeId
------- ------ -------- ---------- ------------------- ------------------- ------ ----------
267 40 25 2042011234 2012-12-10 05:20:30 2012-12-10 05:22:30 1 5
134 20 15 9895697970 2012-12-10 05:20:30 2012-12-10 05:22:30 1 3
预期结果
CallCnt ANBCnt Duration Number Mintime Maxtime TYPE CallTypeId
------- ------ -------- ---------- ------------------- ------------------- ------ ----------
267 40 25 2042011234 2012-12-10 04:57:30 2012-12-10 05:22:30 1 5
134 20 15 9895697970 2012-12-10 04:57:30 2012-12-10 05:22:30 1 3
显示问题的列是 Mintime 应该是Maxtime minus Duration