我有一张这样的表
╔═══════╦════════╗
║ VOL ║ WEIGHT ║
╠═══════╬════════╣
║ 20.00 ║ 222.00 ║
╚═══════╩════════╝
然后我想显示2列之间哪个值更高 这就像......
╔═══════╦════════╦═════════╗
║ VOL ║ WEIGHT ║ TONNAGE ║
╠═══════╬════════╬═════════╣
║ 20.00 ║ 222.00 ║ 222.00 ║
╚═══════╩════════╩═════════╝
答案 0 :(得分:5)
使用GREATEST
SELECT vol, weight, GREATEST(vol, weight) Tonnage
FROM tableName
SOURCE
答案 1 :(得分:2)
我同意之前关于GREATEST
的帖子,但是对于更通用的语法,CASE
效果也很好(应该适用于大多数RDBMS):
SELECT vol,
weight,
case
when vol > weight
then vol
else weight end as Tonnage
FROM tableName