开发者

Query to select maximum of all minimum

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜