我的表就像这样
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
答案 0 :(得分:5)
你会加入最大值并进行分工:
select t.*, x.maxvalue, t.value / x.maxvalue
from t cross join
(select max(value) as maxvalue from t) x;
答案 1 :(得分:2)
试试这个:
select id,value,(select max(value) from mytable) as max_value, value/(select max(value) from mytable) as division from mytable;
答案 2 :(得分:0)
START TRANSACTION;
SET @max_value = (select max(value) from mytable);
Select id, value, @max_value, value/@max_value as div_by_max from mytable;
COMMIT;