这似乎非常多余。我正在做的是为特定员工和他们所在的部门分配任务,并根据 datediff 和后续日期相等的时间在两周内分配他们的任务,分配一个 1,这是真的,总和为结束。
$_2weeks = "select
isnull(b.employee, 'Event Total') as Employee,
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))<='-2' then 1 else 0 end) '2+ Days Behind',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='-1' then 1 else 0 end) '1 Day Behind',
sum(case when cast(a.follow_up as date)=cast(GETDATE() as date) then 1 else 0 end) 'Today<br> " . date('m/d') . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='1' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+1 day')), 0, 1).'<br>' . date('m/d', strtotime('+1 day')) . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='2' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+2 day')), 0, 2).'<br>' . date('m/d', strtotime('+2 day')) . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='3' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+3 day')), 0, 1).'<br>' . date('m/d', strtotime('+3 day')) . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='4' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+6 day')), 0, 1).'<br>' . date('m/d', strtotime('+6 day')) . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='5' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+7 day')), 0, 1).'<br>' . date('m/d', strtotime('+7 day')) . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='6' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+8 day')), 0, 1).'<br>' . date('m/d', strtotime('+8 day')) . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='7' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+9 day')), 0, 2).'<br>' . date('m/d', strtotime('+9 day')) . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='8' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+10 day')), 0, 1).'<br>' . date('m/d', strtotime('+10 day')) . "',
sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='9' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+13 day')), 0, 1).'<br>' . date('m/d', strtotime('+13 day')) . "',
sum(1) AS 'Total'
from " . event_table('event') . " a
left outer join " . event_table('employee') . " b on a.employee_id=b.id
where a.task_id like '%$task_id%'
and b.department_id like '$dept_id'
and a.status=1
and a.task_id<>''
group by b.employee with rollup";
以及 substr 和 strtotime php函数的更简洁的方法?任何帮助将不胜感激。提前致谢。