i pulling historical data firebird
database below:
product_id date price 1 2001-01-01 10 1 2001-02-01 10 1 2001-03-01 15 1 2001-04-01 10 1 2001-05-01 20 1 2001-06-01 20
what trying extract first occurrence every price change. example of expected data set:
product_id date price 1 2001-01-01 10 1 2001-03-01 15 1 2001-04-01 10 1 2001-05-01 20
i know on mssql
leverage lag
that. possible firebird
?
you can try this, aware didn't tested it:
create procedure sp_test returns ( product_id integer, date date, price integer ) declare variable last_product_id integer; declare variable last_date date; declare variable last_price integer; begin select product_id, date, price xxxx order product_id, date product_id, date, price begin if ((:last_product_id null) or (:last_date null) or (:last_price null) or (:product_id <> :last_product_id) or (:price <> :last_price)) suspend; last_product_id = :product_id; last_date = :date; last_price = :price; end; end;
Comments
Post a Comment