I need to create a Progressive Number on different group in a Select on SQL, the number should be progressive with different group , but the same inside the same group.
Here is the code i use now with the result :
select ROW_NUMBER()OVER(PARTITION BY SD.SALEDOCID ORDER BY sd.DOCNO ASC) AS ProgressivoDocumento, sd.SaleDocId , cs.custsupp , 'CINV' AS TipoDocument, sd.DocNo As NumeroDocumento, sd.DocumentDate as DataEmissioneDocumento from MA_SaleDoc SD JOIN MA_PyblsRcvbls PY on sd.DocNo = py.DocNo right join MA_CustSupp CS on cs.CustSupp = sd.CustSupp join MA_SaleDocSummary sds on sd.SaleDocId = sds.SaleDocId join MA_SaleDocPymtSched sdp on sdp.SaleDocId = sd.SaleDocId where ( sd.DocumentType = '3407874'or sd.DocumentType = '3407875') and py.Settled = 0 and sd.DocumentDate >='20210101' and py.DocumentDate >='20210101' AND CS.CustSuppType = '3211264'
And this is what i find
But i need exactly the opposite like this :
Can someone help me on how to solve this?
Thank you very much