Oracle 比较连续的两个值
Oracle Compare two values in a row
我有一个 table 如下所示
value id
yes 1
NO 2
ABC 3
ABC 4
我想比较 id 3 和 4 的值,如果值相同,则需要 return id 1 的值,否则它应该 return id d 的值。
在这种情况下,由于 id 3“ABC”和 4“ABC”的值相同,因此它应该 return“是”。
那么如何比较同一行的值和 return 相应的值?
简单明了(第 1 - 6 行中的示例数据;查询从第 7 行开始):
SQL> with test (value, id) as
2 (select 'yes', 1 from dual union all
3 select 'NO' , 2 from dual union all
4 select 'ABC', 3 from dual union all
5 select 'ABC', 4 from dual
6 )
7 select case when (select value from test where id = 3) =
8 (select value from test where id = 4)
9 then (select value from test where id = 1)
10 else (select value from test where id = 2)
11 end result
12 from dual;
RESULT
----------
yes
SQL>
我有一个 table 如下所示
value id
yes 1
NO 2
ABC 3
ABC 4
我想比较 id 3 和 4 的值,如果值相同,则需要 return id 1 的值,否则它应该 return id d 的值。
在这种情况下,由于 id 3“ABC”和 4“ABC”的值相同,因此它应该 return“是”。
那么如何比较同一行的值和 return 相应的值?
简单明了(第 1 - 6 行中的示例数据;查询从第 7 行开始):
SQL> with test (value, id) as
2 (select 'yes', 1 from dual union all
3 select 'NO' , 2 from dual union all
4 select 'ABC', 3 from dual union all
5 select 'ABC', 4 from dual
6 )
7 select case when (select value from test where id = 3) =
8 (select value from test where id = 4)
9 then (select value from test where id = 1)
10 else (select value from test where id = 2)
11 end result
12 from dual;
RESULT
----------
yes
SQL>