确定某个数字是否大于要求

时间:2013-07-11 02:10:19

标签: mysql

嗨,我在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中执行此操作?

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:2)

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

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

Link to SQLFiddle

答案 2 :(得分: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