spark.sql(
"""
|select
|*
|from(
|select
|class , source,
|rank() over (partition by class order by CAST(source as int) desc) num
|from class
|) t1
|where t1.num<=3
|""".stripMargin).show()
spark.sql(
"""
|select
|*
|from(
|select
|class , source,
|rank() over (partition by class order by CAST(source as int) desc) num
|from class
|) t1
|where t1.num<=3
|""".stripMargin).show()