I start with columns `Week` , `Prod` and `Qty`: 

[![Initial Dataset](https://i.stack.imgur.com/W0yPg.png)](https://i.stack.imgur.com/W0yPg.png)

I'd like my output to be the following : 

[![Desired output](https://i.stack.imgur.com/81nyH.png)](https://i.stack.imgur.com/81nyH.png)

I have used the following excel formulas to get this output: 

In Cell D2 : `=IF(B2=B1, IF(C2=C1, "N", "Y"), "N")`
In Cell E2 : `=IF(D2="N", "NA", C2-C1)`

I'd like to replicate the same in SQL statements. I'm not sure how I can get started.