Return 所有具有基于两列计算的最大值的行

Return all rows with MAX value based on the calculation done on two columns

我有一个名为 'Houses' 的 table,其中包含字段 'house_id'、'house_type'、'bhk_detail'、'bed_count'、'furnishing_type', 'Beds_vacant'.现在我需要编写一个查询来获取bed_count - bed_vacant 占用率最高的房子的详细信息。我试过这样的事情:

SELECT hs.house_id, hs.house_type , hs.bhk_details, hs.bed_count , hs.furnishing_type, hs.Beds_vacant,
       max(hs.bed_count - hs.Beds_vacant
FROM Houses as hs 
GROUP BY hs.house_id, hs.house_type, hs.bhk_details, hs.bed_count, hs.furnishing_type, hs.Beds_vacant 
HAVING MAX(hs.bed_count - hs.Beds_vacant)IN (SELECT max(hs.bed_count - hs.Beds_vacant) FROM Houses as hs) 

查询对我有用,但我想知道我们是否可以更精确地编写它

我认为最简单的方法是top 1 with ties:

select top (1) with ties h.*
from Houses h
order by (h.bed_count - h.beds_vacant) desc;