简体   繁体   English

Mysql select 包含带条件的最大值的行

[英]Mysql select row that contains max value with conditions

I would like to select the row that caontains the max value on a column (rank) with specific conditions: 1: result > 0 2: apply = 17我想 select 在特定条件下包含列(等级)最大值的行:1:结果> 0 2:应用= 17

在此处输入图像描述

this is my sql select这是我的 sql select

SELECT *
FROM mytable
WHERE apply = 17 and result > 0
HAVING MAX(rank)

In this exapmle i should have as output the row with id 11在这个例子中,我应该将 id 为 11 的行设为 output

You are not aggregating here so having is not correct;你没有聚集在这里,所以拥有是不正确的; you want a single row based on an order (by rank) so你想要基于订单(按排名)的单行所以

SELECT *
FROM mytable
WHERE apply = 17 and result > 0
ORDER BY rank DESC
LIMIT 1;

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

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