0
我想從下面的查詢中拉出一行結果(兩個或更多,如果它是一條領帶)。問題是,它返回三行,而不僅僅是一行,其中包含總HP最高的unit_name,這是HP和Shields的組合。查詢返回兩個表上的最高值和名稱兩列
查詢英文 哪個單位有最全面的防禦?
查詢...
select unit_name, max(hp + shield) as totalHealth
from
(
select unit_name, hp, shield from units
where hp = (select max(hp) from units)
union
select unit_name, hp, shield from units
where shield =(select max(shield) from units)
) d
group by unit_name
結果...
unit_name totalhealth
Archon 360
Battlecruiser 550
Mothership 700
我希望查詢將只返回母船和700, 這樣的事情....
unit_name totalHealth
Mothership 700
我使用的是postgres
真棒,謝謝你的解釋。 – user3622460