简体   繁体   English

MySQL选择更大的值以及“大于”子句?

[英]MySQL select the largest value along with greater-than clause?

How to select only one row that has highest value in colum1 , also making sure that the selected colum1 value is greater-than n 如何选择只有一个具有最高 colum1 ,也确保所选择的colum1大于,小于 n

SELECT * FROM thetable WHERE colum1 >= 150 ORDER BY amount LIMIT 1
//using limit to get 1 row
//using where to fulfill greathe-than criteria
//using order by to sort and get max one.

The above query is giving greater-than 150 row but not the maximum one of table, what is wrong in query? 上面的查询给出的行大于150,但没有给出表的最大行,查询中出了什么问题?

You need to use max and having like this hypothetical query. 您需要使用maxhaving这样的假设查询。 Here we are getting the country with the highest number of branches which has more than 7 branches (8 or more): 在这里,我们得到了拥有最多7个分支机构(8个或更多)的分支机构数量最多的国家:

SELECT country,MAX(no_of_branch)
FROM publisher
GROUP BY country
HAVING MAX(no_of_branch)>=8;

More here 这里更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM