MySQL筛选最高值,sql / mysql筛选器,仅包含最大值

I have a resultset that is like this:

ID | name | myvalue

1 | A1 | 22

2 | A2 | 22

3 | A3 | 21

4 | A4 | 33

5 | A5 | 33

6 | A6 | 10

7 | A7 | 10

8 | A8 | 10

9 | A9 | 5

what i want, is to include only rows that contains the highest "myvalue" available (in the previous example is 33), then:

ID | name | myvalue

4 | A4 | 33

5 | A5 | 33

IE the query should pick the highest "myvalue" available (IE 33) and it should remove the rows that have myvalue < 33

SELECT ..... WHERE myvalue = THE_HIGHEST_OF(myvalue)

Hoping to have been clear...

thank you in advance

edit:

my current query is

SELECT

*,

(very long code that returns a integer as relevance score) AS myvalue

FROM

mytable

HAVING

myvalue = ?????

ORDER BY

myvalue DESC

now the highest myvalue can be 10, 20, 30, any number... in the final resultset i want to include only the rows that have the highest possible relevance score

ive tried using GROUP BY, but i always need to repeat the...

(very long code that returns a integer as relevance score) AS myvalue

...twice

解决方案SELECT * FROM t WHERE myValue IN (SELECT max(myValue) From t);

Edit:

As per discussion with OP.

OP wants to use alias in WHERE clause. But you can only use column aliases in GROUP BY, ORDER BY, or HAVING clauses.

Look at this answer.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值