表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
select (case when a>b then a else b end),
(case when b>c then b esle c end)
from table_name
本文介绍了一种使用SQL的case when语句来根据列值进行条件选择的方法。具体地,当A列的值大于B列时,选择A列的值;否则选择B列的值。同样地,当B列的值大于C列时,选择B列的值;否则选择C列的值。通过这种方式,可以灵活地根据数据表中的不同列值进行条件判断。
select (case when a>b then a else b end),
(case when b>c then b esle c end)
from table_name

被折叠的 条评论
为什么被折叠?