- 论坛徽章:
- 0
|
使用 case when 可以处理,但是计算字段数值大小很麻烦啊(而且有局限)
本人很菜~~大家不要笑我的写法
eg:
select * from sort_t;
COL1 COL2 COL3
---------- ---------- ----------
1 3 2
4 2 1
4 7 1
select case when col1<col2 and col1<col3 then col1 When col2<col1 And col2<col3 Then col2 When col3<col1 And col3<col1 Then col3 End new_col1,
case when (col1<col2 and col1>col3) Or (col1>col2 and col1<col3) then col1 when (col2<col1 and col2>col3) Or ((col2>col1 and col2<col3) ) then col2 When (col3<col1 And Col3>col2) Or (col3>col1 And Col3<col2) Then col3 End new_col2,
case when col1>col2 and col1>col3 then col1 When col2>col1 And col2>col3 Then col2 When col3>col1 And col3>col1 Then col3 End new_col3
from sort_t;
NEW_COL1 NEW_COL2 NEW_COL3
---------- ---------- ----------
1 2 3
1 2 4
1 4 7 |
|