mysql min where语句 [英] mysql min where statement

查看:248
本文介绍了mysql min where语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们有mysql MIN()函数来获取表中的最小值...但是如果我想基于条件获取MIN()怎么办

so we have the mysql MIN() function for getting the minimum in a table...but what if I want to get a MIN() based on a criteria

类似MIN(age)WHERE height< 170

so something like MIN(age) WHERE height < 170

其目的是让只有身高为< 170 ...这样说来,山姆是身高小于<的人中最小的一个. 170,但是pam比sam小,但高度> 170,则查询应返回sam而不是pam ...

in which the aim is to get the minimum age of ONLY people whose height is < 170...so say sam is the youngest of those with height < 170, but pam is younger than sam but have height > 170, then the query should return sam instead of pam...

我将如何构成这样的查询?

how would I compose such query?

推荐答案

您说您要仅身高小于170的人的最低年龄"

You say you want the "minimum age of ONLY people whose height is < 170"

SELECT MIN(age)
FROM YourTable
WHERE height < 170

实际上将按您的要求工作!

Will in fact work as you require then!

WHERE限制行预聚合,HAVING可用于过滤聚合结果.

WHERE limits row pre aggregation, HAVING can be used to filter on the results of aggregations.

这篇关于mysql min where语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆