如何只选择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.
上面的查询给出大于 150 行,但不是表的最大行,查询有什么问题?
您需要
使用max
和having
,就像这个假设的查询一样。在这里,我们得到了分支机构数量最多的国家/地区,该分支机构数量超过 7 个(8 个或更多):
SELECT country,MAX(no_of_branch)
FROM publisher
GROUP BY country
HAVING MAX(no_of_branch)>=8;
更多在这里