SELECT SUM(`amount`) AS total_amount,
count(*) AS charge_count
FROM `chargetable`
WHERE appid='123'
AND status='1'
UNION ALL
SELECT SUM(`amount`) AS total_amount,
count(*) AS charge_count
FROM `chargetable`
WHERE appid='123'
AND status='1'
AND ch_created_time >='2015-07-28 00:00:00'
AND ch_created_time <'2015-07-28 01:00:00'
UNION ALL
SELECT SUM(`amount`) AS total_amount,
count(*) AS charge_count
FROM `chargetable`
WHERE appid='123'
AND status='1'
AND ch_created_time >='2015-07-28 01:00:00'
AND ch_created_time <'2015-07-28 02:00:00'
也许有一个MySQL功能可以自动拆分1小时,我找不到它。