SQL-Find 2nd Highest Number


Select coulmn_name(1)coulmn_name(2), Sales_coulmn_name(3)

from (Select coulmn_name(1)coulmn_name(2), Sales_coulmn_name(3), dense_rank() over(order by Sales_coulmn_name desc) as coulmn_name from table_name
Where coulmn_name in ('Condition')
Limit 10)

where ranking_coulmn_name in ('2')

Example

Select listing_Id, buyer_city_repo, delivered_gmv

from (Select listing_Id, buyer_city_repo, delivered_gmv, dense_rank() over(order by delivered_gmv desc) as Ranking from category.food_fmcg_sales
Where buyer_city_repo in ('Delhi')
Limit 10)

where ranking in ('2')

Output


No comments:

Post a Comment