Find the hours for which the product ‘A’ was out of stock, assuming this is all the data for one day only

Question

Product_inv

Product ID   is_in_stock create_dt
A   1 2019-01-01 0:00
A   0 2019-01-01 10:00
A   1 2019-01-01 13:00
A   0 2019-01-01 20:00
A   1 2019-01-01 23:59

 

Find the hours for which the product ‘A’ was out of stock, assuming this is all the data for one day only?

in progress 0
vinod.k 55 years 1 Answer 815 views Member 0

Answer ( 1 )

  1. select concat (‘Product’, ‘not’, ‘avaiable between’,time(P2.Create_dt) ,’and’, time(P1.Create_dt)) as Details from Product_Inv P2
    join Product_Inv P1 on P2.id+1 = P1.id
    where t2.stock =0

    /*Assuming the blank column as ID, if the blank column is not id u can create one using autoincrement and execute the given code */

Leave an answer

Browse
Browse