My table is like this
ID VALUE
1 4
2 6
3 12
I want to get an output in this format in mysql, could you provide me with an appropriate sql for the same
ID VALUE MAX_VALUE DIV_BY_MAX_VALUE
1 4 12 0.33
2 6 12 0.5
3 12 12 1.0
You would join in the maximum and do the division:
select t.*, x.maxvalue, t.value / x.maxvalue
from t cross join
(select max(value) as maxvalue from t) x;
Try this:
select id,value,(select max(value) from mytable) as max_value, value/(select max(value) from mytable) as division from mytable;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With