问题描述
所以我们有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语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!