Teradata SQL을 처음 사용하기 때문에 시작일과 종료일을 기준으로 월별 직원 수를 계산해야합니다. 더 우아한 방법이 있나요SQL - 시작일과 종료일을 기준으로 월별 계산
MonthEnd Emp_Count
1-31-2012 2
2-29-2012 2
3-31-2012 1
4-30-2012 2
: 이제 난 아직도 2012년 4월 30일에 고용이 네 개의 직원 데이터가 있다고 가정 해 봅시다, 그래서이
Emp_ID join_date leave_date
1 1-1-2012 2-02-2012
2 1-17-2012 3-4-2012
3 2-1-2012 1-1-9999
4 3-20-2012 1-1-9999
원하는 출력과 같다 이 일을하는 것보다 선택의 무리를 UNION ALL으로하는 것보다?
select
'1-31-2012' as MonthEnd
Count(Emp_ID) as Emp_Count
where join_date <= MonthEnd and leave_date > MonthEnd
UNION ALL
select
'2-29-2012' as MonthEnd
Count(Emp_ID) as Emp_Count
where join_date <= MonthEnd and leave_date > MonthEnd
UNION ALL
select
'3-31-2012' as MonthEnd
Count(Emp_ID) as Emp_Count
where join_date <= MonthEnd and leave_date > MonthEnd
UNION ALL
select
'4-30-2012' as MonthEnd
Count(Emp_ID) as Emp_Count
where join_date <= MonthEnd and leave_date > MonthEnd
또한 데이터 형식 문제는 이미 처리되었으므로 무시하십시오.