我想写一个case子句,它从内部查询中获取输入。请让我更详细地描述一下。
说我有一张桌子:
创造餐桌食物(fruit varchar2(50), 筹码varchar2(50)…
如果 它必须是子查询 然后用 dual :
dual
select fruit, chips, (select case food.fruit when 'Apple' then 1 else 0 end from dual) is_apple from food;
或从中选择 food 使用主键(如果您的表包含它),或 rowid :
food
rowid
select fruit, chips, case (select fruit from food ff where ff.rowid = food.rowid) when 'Apple' then 1 else 0 end is_apple from food;
的 <子> 演示 子> 强>
您不需要子查询:
select fruit, chips, case when fruit = 'Apple' then 1 else 0 end as is_apple from food
如果值必须是子查询的结果,则可以使用:
select fruit, chips, (select case when f2.fruit = 'Apple' then 1 else 0 end from food f2 where f.rowid = f2.rowid ) from food f