您好,我正在尝试根据最新(最大)版本号获取唯一的 ID 值列表
我的 table 看起来像:
id Version Cost Name Status
---|-----|------------|--------|---------
35 | 1.0 | 200000 | john | Open
36 | 1.0 | 400000 | juliet | Open
35 | 2.0 | 350000 | borat | Closed
36 | 1.5 | 30000 | john | Waiting Update
我希望它能够返回
id Version Cost Name Status
---|-----|------------|--------|---------
35 | 2.0 | 350000 | borat | Closed
36 | 1.5 | 30000 | john | Waiting Update
我尝试过使用它,但无法让它工作,而且我不确定哪里出了问题
select FB.* from CSLL.Feedback FB
inner join (
select ID
,max(Version)
,Status as MaxID
from CSLL.Feedback
group by ID
) groupedID
ON FB.ID = groupedID.ID
AND FB.Version = groupedID.MaxID
and FB.Status = groupedID.Status
这是基于对此处找到的另一个问题的答复
有人可以帮忙吗?
提前非常感谢
汤姆
最佳答案
试试这个。
select fb1.* from Feedback fb1
LEFT JOIN Feedback fb2 on fb2.id=fb1.id and fb2.version>fb1.version
where fb2.id IS NULL;
关于mysql - 从 SQL 存储过程中的唯一值查找最大数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24736443/