有两个数据表City表和Price表,CIty表的结构如下:
Price表的结构如下:
查询每个城市最大的销售价格,并以最大价格进行降序排列,SQL语句的代码如下:
select top 5 * from (select ROW_NUMBER() over(order by TmpTable.AdultyPrice desc) NID, City.*, TmpTable.AdultyPrice from City,(select MAX(Price.AdultyPrice) as AdultyPrice,PID from City inner join Price on City.LID = Price.PID group by Price.PID) as TmpTable where LID = PID) as tmp where tmp.NID between 1 and 5
运行结果:
原文地址:https://www.cnblogs.com/feiyuhuo/p/9069542.html
时间: 2024-10-11 19:13:04