decode(a.revsal_flag,'R','Y',' ','N',a.revsal_flag) 转换成 case when
时间: 2024-01-12 21:02:56 浏览: 28
将 decode(a.revsal_flag,'R','Y',' ','N',a.revsal_flag) 转换成 case when 可以这样写:
```
case a.revsal_flag
when 'R' then 'Y'
when ' ' then 'N'
else a.revsal_flag
end
```
其中,第一个 when 子句表示如果 a.revsal_flag 的值为 'R',则返回 'Y';第二个 when 子句表示如果 a.revsal_flag 的值为空格,返回 'N';否则返回 a.revsal_flag 的原值。
相关问题
decode( bb.PM_FLAG,'Y','Y','N' ) 预约
decode函数是Oracle数据库中的一个函数,它用于将一个值按照指定的规则进行转换。在这个例子中,decode函数的含义是:如果bb.PM_FLAG的值为'Y',则返回'Y',否则返回'N'。
预约是指在医疗领域中,病人预约医生的时间,以便得到更好的服务。在这个问题中,我不清楚预约和decode函数之间是否有任何关系,如果您能提供更多的上下文信息,我将会更好地回答您的问题。
select sum(case when c.id_Dep_Pi_Af = '60877de521997e2901a929a1' and c.sd_Apply_Ap_Cd in ('1', '5') then 1 else 0 end) as depPiInNum, SUM(DECODE(c.ID_DEP_PI_BEF, '60877de521997e2901a929a1', 1, 0)) as depPiOutNum from Hi_Vis_Med a left join Hi_Vis_Med_Ip b on a.id_Vismed = b.id_Vismed left join Hi_Vis_Med_Dep_Pi_Changeap c on b.id_Vismed = c.id_Vismed where a.sd_Vistp_Cd = '114' and a.delete_Flag = 0 and c.sd_Apply_Ap_Cd in ('1', '2', '5', '6'); sql优化
可以尝试以下优化方式:
1. 创建索引:可以在Hi_Vis_Med、Hi_Vis_Med_Ip、Hi_Vis_Med_Dep_Pi_Changeap表中分别创建以下列的索引:id_Vismed、sd_Vistp_Cd、delete_Flag、id_Dep_Pi_Af、sd_Apply_Ap_Cd、ID_DEP_PI_BEF等。
2. 使用EXISTS代替LEFT JOIN:可以将LEFT JOIN改为EXISTS,如下所示:
select sum(case when c.id_Dep_Pi_Af = '60877de521997e2901a929a1' and c.sd_Apply_Ap_Cd in ('1', '5') then 1 else 0 end) as depPiInNum,
SUM(DECODE(c.ID_DEP_PI_BEF, '60877de521997e2901a929a1', 1, 0)) as depPiOutNum
from Hi_Vis_Med a
where a.sd_Vistp_Cd = '114' and a.delete_Flag = 0
and exists (
select 1 from Hi_Vis_Med_Ip b, Hi_Vis_Med_Dep_Pi_Changeap c
where a.id_Vismed = b.id_Vismed and b.id_Vismed = c.id_Vismed and c.sd_Apply_Ap_Cd in ('1', '2', '5', '6')
);
3. 将DECODE函数转成CASE语句:可以将DECODE函数转成CASE语句,如下所示:
select sum(case when c.id_Dep_Pi_Af = '60877de521997e2901a929a1' and c.sd_Apply_Ap_Cd in ('1', '5') then 1 else 0 end) as depPiInNum,
SUM(CASE WHEN c.ID_DEP_PI_BEF = '60877de521997e2901a929a1' THEN 1 ELSE 0 END) as depPiOutNum
from Hi_Vis_Med a
where a.sd_Vistp_Cd = '114' and a.delete_Flag = 0
and exists (
select 1 from Hi_Vis_Med_Ip b, Hi_Vis_Med_Dep_Pi_Changeap c
where a.id_Vismed = b.id_Vismed and b.id_Vismed = c.id_Vismed and c.sd_Apply_Ap_Cd in ('1', '2', '5', '6')
);
相关推荐
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)