У меня есть следующие образцы данных:
declare @table table
(
Tbl char(2)
, TxDate date
, AutoIdx int
, Debit float
, Credit float
, Order_No varchar(50)
, ExtOrderNum varchar(50)
, Reference varchar(50)
, Reference2 varchar(50)
, Description varchar(100)
, AuditNumber varchar(50)
)
insert into @table
(
Tbl
, TxDate
, AutoIdx
, Debit
, Credit
, Order_No
, ExtOrderNum
, Reference
, Reference2
, Description
, AuditNumber
)
values
('GL','2020-03-18',877224,0,2306.9,'PO07673','blue/Prov','60','GRV8399','Purchase Order','26382.0001')
, ('AP','2020-03-18',265586,0,2306.9,'PO07673','blue/Prov','60','GRV8399','Purchase Order','26382.0001')
, ('AP','2020-03-18',265607,0,2306.9,'PO07673','blue/Prov','60','GRV8455','Purchase Order','26391.0001')
, ('GL','2020-03-18',877518,0,2306.9,'PO07673','blue/Prov','60','GRV8455','Purchase Order','26391.0001')
, ('GL','2020-03-18',877530,2.57,0,'PO07673','60',60,'GRV8481','Accounts Payable','26391.0002')
, ('GL','2020-03-18',877525,0,23008.37,'PO07673','60',60,'GRV8481','Purchase Order','26391.0002')
, ('AP','2020-03-18',265608,0,23008.37,'PO07673','60',60,'GRV8481','Purchase Order','26391.0002')
Когда я запускаю этот запрос:
select
rank() over (order by TxDate,AuditNumber) rnk
, *
from @table
, я получаю следующие результаты:
I'm trying to generate a new number according to each different AuditNumber
, however it doesn't count from 1 to 3, but 1,3,5.
I've tried partition by
& row_number
, etc. but then I get only the number 1.
What am I missing?
My Expected Results:
Ожидаемые результаты