我有一个有18列的mySql表,其中每列可以有20,17.5,15或12.5中的一个值
我需要从具有最高值的16列中选择和求和值。
我该怎么做? 非常感谢你的投入,谢谢。
很可能,你应该重新评估你的db设计,无论如何,你可以尝试使用所有COL之间的差减去最后的2
select col1 + col2 + ... +col18 - t3.min2
from my_table
cross join (
select sum(my_col)*(-1) min2
from (
select my_col
from (
select col1 my_col cfrom my_table
union all
select col2 from my_table
union all
select col3 from my_table
....
union all
select col18 from my_table
) t
order by my_col desc limit 2
) t2
) t3