2016-08-25 5 views
0

[Appt_Date] 날짜가 포함 된 정보를 가져 오는 MySQL 테이블이 있습니다. 데이터가 쿼리에 표시되면 날짜 버킷을 만들고 싶습니다. 따라서 0-7 일, 8-14 일, 15-21 일, 22-28 일 또는 29 일 이상 경과 한 총 수를 계산할 수 있습니다.Report Studio에서 날짜 버킷을 만들려고했지만 올바르게 작동하지 않습니다.

case 
when [Appt_Date] between (current_date) and _add_days (current_date,-7) then 1 else 0 
end 

case 
when [Appt_Date] between _add_days(current_date,-8) and _add_days (current_date,-14) then 1 else 0 
end 

case 
when [Appt_Date] between _add_days (current_date,-15) and _add_days (current_date,-21) then 1 else 0 
end 

case 
when [Appt_Date] between _add_days (current_date,-22) and _add_days (current_date,-28) then 1 else 0 
end 

case 
when ([Appt_Date] > _add_days ({current_date},-28)) then 1 else 0 
end 

문제는 모든 날짜가 처음 4 버킷에와 1 29+ 양동이와 0으로 표시한다는 것입니다 : 5 버킷에 대해 다음과 같이

내 날짜 버킷 식이다.

쿼리에 오늘 및 지난 주 필드를 만들었습니다. 투데이 필드 식입니다 : current_date 와 지난 주입니다 : 데이터 Query data sample

_add_days (current_date,-7)

여기

입니다 샘플 당신은 오늘의 날짜와 방법의 모든 Appt_Dates가 29+ 버킷에 볼 수 있습니다.

왜 버킷이 올바르게 작동하지 않습니까?

답변

0

당신은 당신의 betweens

case 
when [Appt_Date] between _add_days (current_date,-7) and (current_date) then 1 else 0 
end 

를 반전 할 필요가 그리고 내가 제대로

당신의 논리를 이해한다면

case 
when ([Appt_Date] < _add_days ({current_date},-28)) then 1 else 0 
end 

을 추정