获得最大限度的不分组 [英] Getting maximum without grouping

查看:118
本文介绍了获得最大限度的不分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这样一张表:

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

通常,当我们选择MAX(年龄)时,它返回(f,6)元组。但我想要的是它应该返回表格,但所有的年龄值将是最大值。如:

  name |年龄
a | 6
b | 6
c | 6
d | 6
e | 6
f | 6

有没有办法做到这一点?

解决方案

试试这个:

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


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?

解决方案

Try this:

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

这篇关于获得最大限度的不分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆