更新时间:2023-11-07 12:59:22
SELECT B.*
FROM BigTable AS B -- Why do SQL questions omit the table names so often?
JOIN (SELECT EAN, MIN(Price) AS Price
FROM BigTable
GROUP BY EAN
) AS P
ON B.EAN = P.EAN AND B.Price = P.Price
ORDER BY B.EAN;
子查询查找每个EAN的最低价格;外部查询查找与EAN和该EAN的最低价格相匹配的详细信息.如果对于给定的EAN,有两个记录具有相同的最低价格,则将同时选择这两个记录.
The sub-query finds the minimum price for each EAN; the outer query finds the details that match the EAN and minimum price for that EAN. If there are two records with the same minimum price for a given EAN, both will be chosen.