答案 0 :(得分:1)
您可以使用subquery
:
select *
from table t
where price = (select min(price) from table where Item = t.Item)
order by Item;
但是,请注意,同一项目有两个相同的 min 价格
修改强>
您可以更改where
子句并使用 limit 子句
select *
from table t
where id = (select id
from table
where Item = t.Item
order by price desc
LIMIT 1)
order by Item;
答案 1 :(得分:0)
尝试加入子查询,查找每个项目的最低价格记录:
SELECT t1.*
FROM yourTable t1
INNER JOIN
(
SELECT Item, MIN(Price) AS min_price
FROM yourTable
GROUP BY Item
) t2
ON t1.Item = t2.Item AND
t1.Price = t2.min_price
ORDER BY
t1.Item;
答案 2 :(得分:0)
我会使用相关的子查询:
select t.*
from t
where t.price = (select min(t2.price) from t t2 where t2.item = t.item)
order by t.item;
为了提高性能,您需要(item, price)
上的索引。
注意:如果每个项目都具有相同的最低价格,则会为每个项目返回多行。如果你想保证一行,那么你可以这样做:
select t.*
from t
where t.id = (select t2.id
from t t2
where t2.item = t.item
order by t2.price desc
limit 1
)
order by t.item;
答案 3 :(得分:0)
试试这个
SELECT * FROM (table name)
GROUP BY项目,价格,型号,颜色,商店ORDER BY项目,价格,型号,颜色,商店ASC