我有一张这样的桌子。
+-------------+-------+-------+-------+-------+-------+
| studentCode | term1 | term2 | term3 | term4 | term6 |
+-------------+-------+-------+-------+-------+-------+
我想返回每行中术语的最大值。
SELECT studentCode, maxterm FROM my_tbl
如何用我的最大值填充maxterm 感谢...
答案 0 :(得分:2)
答案 1 :(得分:1)
select studentCode,
greatest(term1, term2, term3, term4, term5, term6)
from my_tbl;
答案 2 :(得分:0)
只有几列,你可以使用if子句。
SELECT IF(`col_1` > `col_2`, `col_1`, `col_2`) AS max FROM `my_table`
答案 3 :(得分:0)
尝试使用GREATEST:
SELECT studentCode, GREATEST( term1, term2, term3, term4, term5, term6 )
FROM my_tbl