zoukankan      html  css  js  c++  java
  • case...when...简单用法sql说明

    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;
  • 相关阅读:
    解读AppIcon图标设置置信息和App内存警告临界值
    我在外包公司做增删改查有前途么?
    浅议Grpc传输机制和WCF中的回调机制的代码迁移
    2019.NET Conf China(中国.NET开发者峰会)活动全纪录:.NET技术之崛起,已势不可挡
    一位年轻而优秀的.NET开发者的成长点滴
    领域驱动设计-让程序员心中有码(九)
    2019.NET Conf,我们在共同期待
    码农的技术小世界
    .NET Core使用gRPC打造服务间通信基础设施
    坚持写了一年的博客,我有哪些收获
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/6649649.html
Copyright © 2011-2022 走看看