>select pop AS yearmonth, > ifnull((select sum(s2.stock_count) AS sum_stock_count > from c_stock_month_model2 s2 > where s2.pop <= t.pop ),0) AS cum_month_stock_count > from c_stock_month_model t > order by pop; >>
>select pop AS yearmonth, > ifnull((select sum(s2.stock_count) AS sum_stock_count > from c_stock_month_model2 s2 > where s2.pop <= t.pop > and datediff(s2.pop,t.pop)<810),0) AS cum_month_stock_count > from c_stock_month_model t > order by pop; >>