Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a table like
item_id,item_name
1,a
1,b
1,c
2,x
2,y
2,z
Now, I want the output to be like:
surr_key, item_id,item_name, parent_id
1,1,a,-1
2,1,b,1
3,1,c,2
4,2,x,-1
5,2,y,4
6,2,z,5
Here, surr_key is auto_increment and parent_id is the surr_key of precious row for the same item_id.
a is the first item for item_id=1 thus it will be -1 and same with x.
Can anyone help how to achieve it ?
This post answers a slightly different question, but you can use the method to do what you want. Essentially you are looking at the functionality which means that tMap variables are actioned in order from top to bottom and they preserve their values between rows.
You can use compareTo() for Integers or == for primitive type ints