《SQL 进阶教程》 自连接分组排序:练习题1-2-2

   分组排序

   

SELECT
    d1.district,
    d1. NAME,
    (SELECT COUNT(d2.price)
   FROM district_products d2
   WHERE d2.price > d1.price and d1.district= d2.district) + 1 AS rank_1
FROM
    district_products d1
ORDER BY district,rank_1;

猜你喜欢

转载自www.cnblogs.com/newlangwen/p/10579256.html