Sorting [message #654338] |
Sun, 31 July 2016 05:46 |
|
ashlythomas
Messages: 1 Registered: July 2016
|
Junior Member |
|
|
I have the following data in my database table.
rec_id description parent_id ip_address is_parent
100 Record 1 1000 80.160.4.5 1
101 child 1000 169.60.5.20 0
105 child 1000 169.60.5.20 0
103 Record 2 1002 80.160.4.3 1
104 child 1002 169.60.2.5 0
102 Record 3 1001 80.160.4.2 1
I want a sorting based on the column: ip_address of records where is_parent = 1
The parent record should be listed first and the corresponding child should list immediately after the parent.
The result should be as given below:
rec_id description parent_id ip_address is_parent
102 Record 3 1001 80.160.4.2 1
103 Record 2 1002 80.160.4.3 1
104 child 1002 169.60.2.5 0
100 Record 1 1000 80.160.4.5 1
101 child 1000 169.60.5.20 0
105 child 1000 169.60.5.20 0
Can anyone please help on achieving this?
|
|
|
Re: Sorting [message #654340 is a reply to message #654338] |
Sun, 31 July 2016 09:46 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
You could use min(ip_address) over (partition by parent_id) order by that then by ip_address assuming that the parent id will always have the lowest ip within the group.
Fraid I can't test that at the moment as I'm answering on my phone.
[Updated on: Sun, 31 July 2016 09:53] Report message to a moderator
|
|
|
|
|
|
|
|