sql - Improve query performance instead of aggregrate function -


i have query want change sales_date '01.01.2017' 1st record product. means want every unique product stored in product_id , check first sales_date on product loaded , change sales_date '01.01.2017'.

i have used below query working hitting performance seems. there other can write same logic , improves performance?

    update test_group sd set sales_date = to_date ('01.01.2017', 'dd.mm.yyyy') sales_date =  ( select min(sales_date)    test_group sd2    sd.product_id = sd2.product_id     )  , sd.sales_date  <> to_date ('01.01.2017', 'dd.mm.yyyy');  

using merge statement may improve performance:

merge test_group tgt   using (select product_id,                 rowid r_id,                 row_number() on (partition product_id order sales_date) rn            test_group) src     on (tgt.rowid = src.r_id , src.rn = 1) when matched   update set sales_date = to_date('01.01.2017', 'dd.mm.yyyy')   sales_date != to_date('01.01.2017', 'dd.mm.yyyy'); 

adding index on (product_id, sales_date) (if doesn't exist) should aid performance on both merge , original update statement.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -