0

嗨,我在 MYSQL 中有一个表

  prices

cost  name
3.10  salt
4.00  soda
1.00  bread
1.50  candy
3.50  bread
4.00  candy

我希望能够只显示所有项目都超过 3.00 的项目

所以像

cost  name
3.10  salt
4.00  soda

将是我的结果

我怎样才能在 MYSQL 中做到这一点?

4

3 回答 3

3
SELECT p1.*
FROM prices p1
JOIN (SELECT name, MIN(cost) mincost
      FROM prices
      GROUP BY name
      HAVING mincost > 3) p2
ON p1.name = p2.name
于 2013-07-11T02:12:51.973 回答
2

您可以在子查询或联接中使用 min 。

select * from prices
  where name in (select name from prices group by name having min(cost) > 3);

链接到 SQLFiddle

于 2013-07-11T02:12:42.930 回答
0
select cost,name from prices where cost>3.00 order by name;

输出将是

cost  name
3.50  bread
4.00  candy
3.10  salt
4.00  soda
于 2013-07-11T02:43:28.630 回答