Mysql搜索特定的标准

时间:2018-02-15 04:34:16

标签: mysql

我在rstudio中编码mysql,我想找到一行显示最小weight_g(以克为单位的重量)。然后我使用下面的命令,但它显示错误。

  

Q(“从*中选择*,其中Weight_g = min(Weight_g)”)   [1]“HY000 1111 [MySQL] [ODBC 5.3(w)驱动程序] [mysqld-5.7.17-log]无效使用组功能”
  [2]“[RODBC]错误:无法SQLExecDirect'从bl中选择*,其中Weight_g = min(Weight_g)'”

我遇到此错误消息,非常感谢任何帮助!谢谢!

2 个答案:

答案 0 :(得分:1)

您可以在子查询中获得最小值,

select * 
from bl 
where Weight_g = (SELECT min(Weight_g) from bl)

如果您不关心重复并希望只获得一个值,那么ORDER BYLIMIT就足够了,

select * 
from bl 
ORDER BY Weight_g ASC
LIMIT 1

答案 1 :(得分:0)

尝试不重复:

select * 
from bl 
ORDER BY Weight_g ASC
LIMIT 1;

或者这些以最小权重获得所有不同的实例:

select A.*
from bl A
where 
A.weight_g=(select weight_g from bl ORDER BY weight_g ASC
LIMIT 1);

或者:

select A.*
from bl A
where 
A.weight_g=(select min(weight_g) from bl);