开发者

Query to select maximum of all minimum

开发者 https://www.devze.com 2023-02-22 00:56 出处:网络
I want to extract a row, with the max value in one field but is less than a certain value of that value;

I want to extract a row, with the max value in one field but is less than a certain value of that value;

Fore example,

SELECT id,max(val) WHERE val<23

Here, I need the value of the maximum of field val but which must be less than 23. This works and gives me, the maxi开发者_StackOverflow中文版mum values, but the id field is not respective to that field, it provides the id of the first occurence.

What is the right query?


How about:

SELECT id, val FROM table WHERE val < 23 ORDER BY val DESC LIMIT 1


Try this:

SELECT ID, VAL
FROM [TABLE]
WHERE VAL = (SELECT MAX(VAL) FROM [TABLE] WHERE VAL < 23)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号