我需要有关MySQL 5.5的查询的帮助
在按location_id,count_number,try_number对行进行排序之后,我尝试仅选择2列组合(棕褐色,location_id)中的1行。所以基本上我想有一个查询,该查询仅返回下图中的黄色行。该组中tan / location_id与“ count_number”和“ try_number”最高的组合中只有1条记录。
这是我目前拥有的查询。
select tan, quantity, count_number, try_number, location_id
from inventario_inventoryregistry
where tan = '53-100554-01'
order by location_id desc, count_number desc, try_number desc;
最佳答案
我认为这可以满足您的需求:
select iir.*
from inventario_inventoryregistry iir
where (count_number, try_number) = (select iir2.count_number, iir2.try_number
from inventario_inventoryregistry iir2
where iir2.tan = iir.tan and iir2.location_id = iir.location_id
order by iir2.count_number desc, iir2.try_number desc
limit 1
);