想象下面的(简化的)数据库布局: 我们有很多“假日”logging,涉及到某个特定date的特定住宿等。 我想从数据库中获得每个住宿(即最低价格)的“最佳”假期,给定一组search标准(例如持续时间,离开机场等)。 将有多个相同价格的logging,所以我们需要select保存(降序),然后按出发date升序。 我可以写SQL来做这个看起来像这样(我不是说这是最好的方式): SELECT * FROM Holiday h1 INNER JOIN ( SELECT h2.HolidayID, h2.AccommodationID, ROW_NUMBER() OVER ( PARTITION BY h2.AccommodationID ORDER BY OfferSaving DESC ) AS RowNum FROM Holiday h2 INNER JOIN ( SELECT AccommodationID, MIN(price) as MinPrice FROM Holiday WHERE TradeNameID = 58001 /*** Other Criteria Here ***/ GROUP BY AccommodationID ) […]