cerebalbore
Technical User
Hi all,
I need some help getting the next record in sequence - I have already tried numerous things to get this done and haven't found an answer that will do what I want. The only thing I have found out is that what I want to do isn't 'good practice'.
So here's a snippet of my table...
Order_no Op_no Op_desc
10001 0025 Kitting
10001 0050 Auditing
10001 0100 Release kit
10002 0050 Auditing
10002 0100 Release kit
10002 0150 Validate serial nos
10003 0700 Assembly
10003 0800 Inspect
10003 0900 Receive finished goods
And here's what I want as a result set...
Order_no Op_no Op_desc Next_op
10001 0025 Kitting 0050
10001 0050 Auditing 0100
10001 0100 Release kit
10002 0050 Auditing 0100
10002 0100 Release kit 0150
10002 0150 Validate serial nos
10003 0700 Assembly 0800
10003 0800 Inspect 0900
10003 0900 Receive finished goods
Basically, all the time the order number is the same as the one below it, I want the op number (and other details later) of the next record. The data needs to be sorted by order number then op number.
Some of the operations will not have a next operation as it will be the last one in the sequence for that order.
It's so I can identify what the next stage in the operation sequence an order is due to go to (it will be combined with another couple of tables later). It's to do with what work is at what stage.
Any help is appreciated - I'm ok with the basics of SQL, like nested queries and ctes, but that's as far as it goes!
Thanks
Kat
I'm such a noob
I need some help getting the next record in sequence - I have already tried numerous things to get this done and haven't found an answer that will do what I want. The only thing I have found out is that what I want to do isn't 'good practice'.
So here's a snippet of my table...
Order_no Op_no Op_desc
10001 0025 Kitting
10001 0050 Auditing
10001 0100 Release kit
10002 0050 Auditing
10002 0100 Release kit
10002 0150 Validate serial nos
10003 0700 Assembly
10003 0800 Inspect
10003 0900 Receive finished goods
And here's what I want as a result set...
Order_no Op_no Op_desc Next_op
10001 0025 Kitting 0050
10001 0050 Auditing 0100
10001 0100 Release kit
10002 0050 Auditing 0100
10002 0100 Release kit 0150
10002 0150 Validate serial nos
10003 0700 Assembly 0800
10003 0800 Inspect 0900
10003 0900 Receive finished goods
Basically, all the time the order number is the same as the one below it, I want the op number (and other details later) of the next record. The data needs to be sorted by order number then op number.
Some of the operations will not have a next operation as it will be the last one in the sequence for that order.
It's so I can identify what the next stage in the operation sequence an order is due to go to (it will be combined with another couple of tables later). It's to do with what work is at what stage.
Any help is appreciated - I'm ok with the basics of SQL, like nested queries and ctes, but that's as far as it goes!
Thanks
Kat
I'm such a noob