Oracle SQL - How to get diff between values in same row, no unique ID -


i learning oracle sql.

i need determine time between each purchased/return transaction given product.

a sample of data shown below. there no unique transaction identifier linking purchase return however, can assume return following purchase (based on transactiontime) same transaction.

can please let me know how go solving this? sample sql statement appreciated.

product transactiontype  transactiontime       purchase         18-aug-17 10.15.56.000000       return           18-aug-17 10.30.21.000000       purchase         18-aug-17 11.10.35.000000       return           18-aug-17 11.12.52.000000 b       purchase         18-aug-17 10.15.56.000000 b       return           18-aug-17 10.22.56.000000 b       purchase         18-aug-17 10.30.21.000000 b       return           18-aug-17 10.31.21.000000 

you can use lead():

select t.*,        (next_ttime - transactiontime) time_to_return (select t.*,              lead(transactiontype) on (partition product order transactiontime) next_ttype,              lead(transactiontime) on (partition product order transactiontime) next_ttime       t      ) t transactiontype = 'purchase' ,       next_ttype = 'return' 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -