0
我有包含類似於以下數據的表。我需要的查詢將導致桔子和蘋果具有最高城市ID值的最佳結果。僅使用其他唯一列爲特定記錄選擇最高值?
id | fruit | attr | cityID | personID
163 Apple green 3685 235
163 Apple red 3145 267
163 Apple yellow 1522 560
164 Orange big 1344 147
164 Orange small 833 2673
我需要將
id | fruit | attr | cityID | personID
163 Apple green 3685 235
164 Orange big 1344 147
結果我開始嘗試用
select
fruit_id,
fruit,
attr,
max(cityID),
personID
from fruits_cities
group by
fruit_id,
fruit,
attr,
max(cityID),
personID