用于过滤星期六和星期日的SQL查询

时间:2014-11-19 12:49:30

标签: mysql sql date filter

我有一个复杂的SQL查询,可以计算两次工时。 工作时间如下 周一至周五上午9点至下午6点 周六上午9点到下午1点 周日休息

两列是createdclosed。现在如果创建日期是星期六它应该计算创建时间直到下午1点+(关闭 - 上午9点)星期一。星期一应该是0.如何实现???

$
SELECT `id` as 'No', `subject`, `status`, `created`, `closed`,
case
when (date(ot.`created`) = date(ot.`closed`))  then
      concat( '0 days ', FLOOR(hour(TIMEDIFF(`closed`, `created`))),' hours ',
      (case
        when minute(TIMEDIFF(`closed`, `created`)) < 10 then
        concat( minute(TIMEDIFF(`closed`, `created`)), ' minutes')
        else
        concat(((FLOOR(minute(`created`)/10)) +1), '0 minutes')end))
        when (date(date_add(ot.`created`, INTERVAL 1 day)) = date(ot.`closed`))  
        then case when hour(`created`)>'18' then
                  concat( FLOOR(((hour(`closed`)-9) )/9),' days ',
                  MOD(( (hour(`closed`)-9) ), 9), ' hours ',
                  ((FLOOR(minute(`created`)/10)) +1), '0 minutes' )
                  else
                  concat( FLOOR(( (18-hour(`created`)) + (hour(`closed`)-9) )/9),' days ',
        MOD(( (18-hour(`created`)) + (hour(`closed`)-9) ), 9), ' hours ',
        ((FLOOR(minute(`created`)/10)) +1),'0 minutes' ) end
    when (date(ot.`created`) <= date(date_add(ot.`closed`, INTERVAL 1 day)))  
    then concat( FLOOR(( (18-hour(`created`)) + ((DATEDIFF( `closed`, `created`)-1)*9) + (hour(`closed`)-9) )/9),' days ',MOD(( (18-hour(`created`)) + ((DATEDIFF( `closed`, `created`)-1)*9) + (hour(`closed`)-9) ), 9), ' hours ', ((FLOOR(minute(`created`)/10)) +1),'0 minutes' ) end as TAT,
FROM MyOffice ot inner join 
WHERE ot.`status`='closed' and month(`created`)='10'
order by TAT desc
%$

0 个答案:

没有答案