我正在尋找在我的輸出底部添加一行,其中包含'duration'列的總數。mysql查詢中單個列的總時間
這裏是我的查詢:
SELECT d.id AS 'id',
d.NAME AS 'name',
a.start_time AS 'start time',
a.end_time AS 'end time',
Time_format(Timediff(a.end_time, a.start_time), '%H:%i') AS 'duration',
a.appointment_type AS
'appointment type'
FROM demographic d
INNER JOIN appointment a
ON (d.id = a.id)
WHERE (a.appointment_date BETWEEN
'2016-10-30 00:00:00' AND '2016-10-31 23:59:59');
這裏是我的輸出:
+------+-------------------+------------+----------+----------+-----------------------+
| id | name | start time | end time | duration | appointment type |
+------+-------------------+------------+----------+----------+-----------------------+
| 7615 | Ricky Fenson | 15:45:00 | 16:14:00 | 00:29 | Phone Call |
| 3329 | Keith Richards | 11:30:00 | 11:59:00 | 00:29 | Drop In |
| 455 | Mick Jagger | 14:00:00 | 14:29:00 | 00:29 | Drop In |
| 2346 | Brian Jones | 10:00:00 | 10:29:00 | 00:29 | Drop In |
| 3332 | Bill Wyman | 11:00:00 | 11:29:00 | 00:29 | Drop In |
+------+-------------------+------------+----------+----------+-----------------------+
我想的是:
+------+-------------------+------------+----------+----------+-----------------------+
| id | name | start time | end time | duration | appointment type |
+------+-------------------+------------+----------+----------+-----------------------+
| 7615 | Ricky Fenson | 15:45:00 | 16:14:00 | 00:29 | Phone Call |
| 3329 | Keith Richards | 11:30:00 | 11:59:00 | 00:29 | Drop In |
| 455 | Mick Jagger | 14:00:00 | 14:29:00 | 00:29 | Drop In |
| 2346 | Brian Jones | 10:00:00 | 10:29:00 | 00:29 | Drop In |
| 3332 | Bill Wyman | 11:00:00 | 11:29:00 | 00:29 | Drop In |
| | | | | 02:25 | |
+------+-------------------+------------+----------+----------+-----------------------+
的02:25(總持續時間)是什麼我在之後。
見http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-我要一個非常簡單的sql查詢 – Strawberry