gpt4 book ai didi

mysql如何在结果集中选择一列的最大值作为另一列

转载 作者:可可西里 更新时间:2023-11-01 07:51:34 26 4
gpt4 key购买 nike

我的 table 是这样的

ID  VALUE  
1 4
2 6
3 12

我想在mysql中得到这种格式的输出,你能提供给我吗相同的适当的 sql

ID   VALUE  MAX_VALUE DIV_BY_MAX_VALUE  
1 4 12 0.33
2 6 12 0.5
3 12 12 1.0

最佳答案

您将加入最大值并进行除法:

select t.*, x.maxvalue, t.value / x.maxvalue
from t cross join
(select max(value) as maxvalue from t) x;

关于mysql如何在结果集中选择一列的最大值作为另一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36969925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com