码迷,mamicode.com
首页 > 其他好文 > 详细

8.03 确定两个日期之间的工作日数目

时间:2017-09-14 23:58:24      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:工作日   sele   else   nes   max   end   where   sum   diff   

问题:给定两个日期,求它们之间(包括这两个日期本身)有多少个”工作“日。
select sum(case
             when date_format(
             date_add(jones_hd,interval t500.id - 1, ‘DY‘),‘%a‘)
             in (‘SAT‘, ‘SUN‘) 
             then 0 else 1
           end) as days
  from (select max(case
                     when ename = ‘BLAKE‘ then
                      hiredate
                   end) as blake_hd,
               max(case
                     when ename = ‘JONES‘ then
                      hiredate
                   end) as jones_hd
          from emp
         where ename in (‘BLAKE‘, ‘JONES‘)) x,
       t500
 where t500.id <= datediff(blake_hd, jones_hd) + 1 ;

8.03 确定两个日期之间的工作日数目

标签:工作日   sele   else   nes   max   end   where   sum   diff   

原文地址:http://www.cnblogs.com/liang545621/p/7523298.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!