有没有可能的方法来优化这个联合所有的SQL?

时间:2015-07-28 02:34:45

标签: mysql

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小时,我找不到它。

0 个答案:

没有答案