case...when...简单用法sql说明
2024-08-31 08:23:06
1、项目用到的sql展示
select
n.name,n.position,
case
when
(select count(*) from T_PUNISHMENT c where c.user_id = n.id) > 0
then
'有'
else
'无'
end PUNISHMENT,
case
when
(select count(*) from T_ASK_AND_CONVERSATION c where c.user_id = n.id) > 0
then
'有'
else
'无'
end CONVERSATION,
case
when
(select count(*) from T_REPORT_ON_WORK b where b.user_id = n.id) > 0
then
'有'
else
'无'
end REPORT_WORK,
case
when
(select count(*) from T_INTEGRITY_ASSESS_REPORT b where b.user_id = n.id) > 0
then
'有'
else
'无'
end REPORT_ASSESS
from tor_horizon_user_dept m,to_horizon_user n where m.dept_id = (
select dept_id from tor_horizon_user_position thup,to_horizon_position thp,TOR_HORIZON_USER_DEPT thud where
thup.user_id = 'HZc18c545ab19f94015ab1c564fa00ff' and thp.position_type_id ='HZc18ca15a83d637015a87d8c0550682'
and thup.position_id = thp.id and thup.user_id = thud.user_id) and m.user_id = n.id;
2、项目用到的sql展示
select s.*,
case
when
(select 3+(to_char(trunc(sysdate,'yyyy'),'yyyy')-substr(work_begin_time, 0, 4)-1)*2 as total_vacation_day from t_work_duration u where u.card_no = s.card_no) > 7
then
7
else
(select 3+(to_char(trunc(sysdate,'yyyy'),'yyyy')-substr(work_begin_time, 0, 4)-1)*2 as total_vacation_day from t_work_duration u where u.card_no = s.card_no)
end total_vacation_day
from
(
select p.id,p.name,p.card_no,p.work_begin_time,p.unit_work_time,p.enjoy_summer_winter,p.vacation_begin_time,p.vacation_end_time,q.already_vacation_day,
q.all_vacation_day from t_work_duration p left join
(
select m.id,m.name,m.card_no,m.work_begin_time,m.unit_work_time,m.enjoy_summer_winter,m.vacation_begin_time,
m.vacation_end_time,n.already_vacation_day,t.all_vacation_day from t_work_duration m,
(
select card_no,sum(VACATE_DAY) as already_vacation_day
from T_VACATION,(select trunc(sysdate,'y') as first_day FROM DUAL)m,(select last_day(add_months(trunc(SYSDATE,'y'),11)) as last_day from dual)n
where to_date(vacate_begin_time,'yyyy-MM-dd') >= m.first_day and to_date(vacate_begin_time,'yyyy-MM-dd') <= n.last_day
group by card_no
)n,
(
select card_no,sum(VACATE_DAY) as all_vacation_day from T_VACATION
group by card_no
)t
where m.card_no = n.card_no and m.card_no = t.card_no
)q on p.card_no = q.card_no
)s;
最新文章
- Syncfusion的社区许可及免费电子书和白皮书
- JavaSE的知识
- zend studio 注释快捷键
- ios基础篇(九)——自定义UITabBar
- atoi()函数的实现
- Android内存优化解决 资料和总结的经验分享
- Java中循环删除list中元素的方法总结
- openstack 的 policy 问题。
- Chapter 4.开放-封闭原则
- Linux下同时运行不同版本的qt程序
- C++学习笔记——STL(标准模板库)
- 温故而知新----stack
- [Luogu 3810]三维偏序
- 《机器学习实战》之一:knn(python代码)
- Kotlin的参考资料
- JVM(一):方法区
- java 适配器模式(adapter pattern)
- C#面向对象设计的七大原则
- ios简单国际化
- Python之路(第二十四篇) 面向对象初级:多态、封装
热门文章
- 【POJ 2752 Seek the Name, Seek the Fame】
- 切换cmd的目录
- bigdecimal的使用
- iphone上做webapp时总会识别一串数字为手机号码并变黑显示
- NGINX: 优化 use 参数
- jquery 追加元素的方法(append prepend after before 的区别)
- DNS 资源记录解释
- 函数atof,atoi,atol,strtod,strtol,strtoul 描述
- [MySQL] 锁/死锁问题一例
- C++ 采集音频流(PCM裸流)实现录音功能