简体   繁体   English

mysql在所有行上左联接最大值

[英]mysql left join max value on all rows

I have the following table: 我有下表:

Table Scores: 表分数:

+----+-------+
| Id | value |
+----+-------+
|  1 |   300 |
|  2 |   300 |
|  3 |   300 |
|  4 |   100 |
|  5 |   200 |
+----+-------+

What I need as a result of the query: 由于查询的结果,我需要什么:

+----+-------+
| Id | value |
+----+-------+
|  1 |   300 |
|  2 |   300 |
|  3 |   300 |
|  4 |   300 |
|  5 |   300 |
+----+-------+

With what query can I achieve this? 我可以通过什么查询来实现?

(this is just part of a complex query, this would help a lot to minimize my code) (这只是一个复杂查询的一部分,这将有助于最大程度地减少我的代码)

You could cross join the table with a query that returns the max value: 您可以使用返回最大值的查询来cross join表:

SELECT     id, max_value
FROM       scores
CROSS JOIN (SELECT MAX(value) AS max_value 
            FROM scores) m

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

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