row_number with duplicity [message #681751] |
Wed, 26 August 2020 04:57  |
mape
Messages: 298 Registered: July 2006 Location: Slovakia
|
Senior Member |
|
|
Hello
I would like to get know how to write a right select with sorted records.
For instance I got a records:
contract startdatetime enddatetime cost
358880810 13.07.2020 22:43:09 NULL -2.14
358880810 13.07.2020 22:43:09 13.07.2020 22:43:09 2.64805
And I need to put it in order by rule: when cost >0 then the first row and the rest
I tried it (see below) but not ok:
select row_number() OVER( PARTITION BY contract ORDER BY nvl(enddatetime, startdatetime) ,
CASE WHEN cost<0 then startdatetime
ELSE enddatetime END ASC)
Does anybody know how to write a right ??
Thanks
Regards
MArtin
|
|
|
|
|
|