Getting maximum without grouping

拥有回忆 提交于 2019-12-12 22:11:35

问题


Say that I have a table like that:

name | age
a    | 1
b    | 2
c    | 3
d    | 4
e    | 5
f    | 6

Normally, when we select MAX(age), it returns (f,6) tuple. But what I want is that it should return the table as it is, but all of the age values will be the maximum. Such as:

name | age
a    | 6
b    | 6
c    | 6
d    | 6
e    | 6
f    | 6

Is there a way to do this?


回答1:


Try this:

SELECT `name`,
       (SELECT MAX(age) FROM MyTable) AS `age`
FROM MyTable;


来源:https://stackoverflow.com/questions/9712660/getting-maximum-without-grouping

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!