[Solved] Get the highest price with smaller ID when two ID have the same highest price in Scala


Try this.

scala> val df = Seq((4, 30),(2,50),(3,10),(5,30),(1,50),(6,25)).toDF("id","price")
df: org.apache.spark.sql.DataFrame = [id: int, price: int]

scala> df.show
+---+-----+
| id|price|
+---+-----+
|  4|   30|
|  2|   50|
|  3|   10|
|  5|   30|
|  1|   50|
|  6|   25|
+---+-----+


scala> df.sort(desc("price"), asc("id")).show
+---+-----+
| id|price|
+---+-----+
|  1|   50|
|  2|   50|
|  4|   30|
|  5|   30|
|  6|   25|
|  3|   10|
+---+-----+

solved Get the highest price with smaller ID when two ID have the same highest price in Scala