mysql - fill in data and missing dates -


i trying use sql take current query results:

 +------------+------------+------------+ | store_num  |  price     | date_chng  | +------------+------------+------------+ | 100        |  1.50      | 2014-05-01 | | 100        |  1.52      | 2014-05-03 | | 100        |  1.48      | 2014-05-05 | | 100        |  1.51      | 2014-05-10 | +------------+------------+------------+ 

and them more this, missing dates added, value of price filled in well:

 +------------+------------+------------+ | store_num  |  price     | date_chng  | +------------+------------+------------+ | 100        |  1.50      | 2014-05-01 | | 100        |  1.50      | 2014-05-02 | | 100        |  1.52      | 2014-05-03 | | 100        |  1.52      | 2014-05-04 | | 100        |  1.48      | 2014-05-05 | | 100        |  1.48      | 2014-05-06 | | 100        |  1.48      | 2014-05-07 | | 100        |  1.48      | 2014-05-08 | | 100        |  1.48      | 2014-05-09 | | 100        |  1.51      | 2014-05-10 | +------------+------------+------------+ 

any help/advice/resources appreciated.

thanks!

try:

select "store_num", "price", "date_chng" + x - 1 "date_chng" (   select *,        lead("date_chng") on (order "date_chng" ) - "date_chng" number_of_days   table1 ) m, lateral (   select generate_series( 1,                           case coalesce(m.number_of_days, 1)                          when 0 1                          else coalesce(m.number_of_days, 1) end) x ) y 

demo ==> http://sqlfiddle.com/#!15/3c5a47/2


this query works on version 9.3 only, earlier versions don't support lateral join


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -