mysql min where 语句
所以我们有 mysql MIN() 函数来获取表中的最小值...但是如果我想根据一个标准获取 MIN()
,比如 MIN(age) WHERE height << 170
,其中的目标是仅获得身高 < 170 的人的最低年龄。 170...所以说山姆是身高<170的人中最年轻的170,但pam比sam年轻,但身高> 170 170,那么查询应该返回 sam 而不是 pam...
我将如何编写这样的查询?
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
so something like MIN(age) WHERE height < 170
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说你想要“只有身高<170的人的最低年龄”
实际上会按照你的要求工作!
WHERE
限制行预聚合,HAVING
可用于过滤聚合结果。You say you want the "minimum age of ONLY people whose height is < 170"
Will in fact work as you require then!
WHERE
limits row pre aggregation,HAVING
can be used to filter on the results of aggregations.