今天遇到sql语句中要判断不知道怎么做,于是找了一下,哈哈oracle挺强的
先看case when 语句:
select case when c.store_amount-c.amount > 0 then '盘盈'
when c.store_amount-c.amount < 0 then '盘亏'
else '持平' end from sghis.pa_pham_check_detail c'
decode语句:
select t.employee_id,
t.employee_name,
decode(t.sex , '1' , '男', '2' , '女', ' ') as sex,
t.age,
a.office_name,
t.office_code,
b.dmmc || ' ' as work_p,
t.work_position,
t.doctor_code || ' ' as doctor_code,
e.dmmc,
t.technic_title,
t.py_code,
t.wb_code
from sghis.hd_employee t,
sghis.hd_office_dict a,
(select c.dmsb, c.dmmc
from sghis.hd_gy_dmzd c
where c.dmlb = '7'
and c.xtsb = '0') b,
(select d.dmsb, d.dmmc
from sghis.hd_gy_dmzd d
where d.dmlb = '8'
and d.xtsb = '0') e
where t.office_code = a.office_code
and t.work_position = b.dmsb(+)
and t.technic_title = e.dmsb(+)
and t.hos_id = '$P!{hos_id}'
and t.employee_name like '%$P!{employee_name}%'
and t.office_code like '%$P!{office_code}%'
and t.py_code like '%$P!{py_code}%'
and t.wb_code like '%$P!{wb_code}%'
order by t.office_code
先看case when 语句:
select case when c.store_amount-c.amount > 0 then '盘盈'
when c.store_amount-c.amount < 0 then '盘亏'
else '持平' end from sghis.pa_pham_check_detail c'
decode语句:
select t.employee_id,
t.employee_name,
decode(t.sex , '1' , '男', '2' , '女', ' ') as sex,
t.age,
a.office_name,
t.office_code,
b.dmmc || ' ' as work_p,
t.work_position,
t.doctor_code || ' ' as doctor_code,
e.dmmc,
t.technic_title,
t.py_code,
t.wb_code
from sghis.hd_employee t,
sghis.hd_office_dict a,
(select c.dmsb, c.dmmc
from sghis.hd_gy_dmzd c
where c.dmlb = '7'
and c.xtsb = '0') b,
(select d.dmsb, d.dmmc
from sghis.hd_gy_dmzd d
where d.dmlb = '8'
and d.xtsb = '0') e
where t.office_code = a.office_code
and t.work_position = b.dmsb(+)
and t.technic_title = e.dmsb(+)
and t.hos_id = '$P!{hos_id}'
and t.employee_name like '%$P!{employee_name}%'
and t.office_code like '%$P!{office_code}%'
and t.py_code like '%$P!{py_code}%'
and t.wb_code like '%$P!{wb_code}%'
order by t.office_code