Skip to content

Instantly share code, notes, and snippets.

@dmitrymomot
Created July 12, 2013 11:49
Show Gist options
  • Save dmitrymomot/5983879 to your computer and use it in GitHub Desktop.
Save dmitrymomot/5983879 to your computer and use it in GitHub Desktop.
SELECT
`calldate`,
COUNT(`duration`) as count_all_calls,
SUM(IF((`duration`-12)>0, 1, 0)) as count_paid_calls,
SUM(`duration`) as summ_all_second,
SUM(IF(`duration`>12, `duration`-12, 0)) as summ_paid_second,
CEILING(SUM(`duration`)/60) as summ_all_minutes,
CEILING(SUM(IF((`duration`-12)>0, `duration`-12, 0))/60) as summ_paid_minutes
FROM `cdr`
WHERE `calldate` BETWEEN '2012-06-13 12:00:00' and '2012-06-13 18:00:00'
GROUP BY DATE(`calldate`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment