interval by 4 using sql - Mysql -
i've table , want data interval 4 or, when i'm using modulo record not expected, pfb `
select (date_format(subscribed_from, '%y-%m')) date_ subscription operator = 'tim' , date_format(subscribed_from, '%y-%m-%d') between '2013-01-01' , '2014-12-31' group (date_format(subscribed_from, '%y-%m'));
it show record this
2013-01 2013-02 2013-03 2013-04 2013-05 2013-06 2013-07 2013-08 2013-09
i want take data interval 4, below record expected.
2013-01 2013-05 2013-09 2014-02
and interval 2, below record expected
2013-01 2013-03 2013-05 2013-07 2013-09
if using modulo % 2
start 2013-01 , jump 2, problem if range want start 2013-02, 02 self not showing on result. if clause month start 2 given interval such 2,4,6,8,10,12
select date_, sum(the_metric_you_want_to_aggregate) ( select 4*floor( (date_format(subscribed_from, '%y%m') - 201301) /4) date_, the_metric_you_want_to_aggregate subscription operator = 'tim' , subscribed_from between 20130101000000 , 201412315959 ) ilv group date_
(where 201301 year/month start of range selecting - assuming reference 4-month aggregation)
note enclosing column references in functions (...date_format(subscribed_from, '%y-%m-%d') between...
) prevents use of indexes.
Comments
Post a Comment