1월과 2월에대한 쿼리만 보여드리겠습니다.. (mo는 당월값 mc는 누적값)
select rank,
isnull(max(case when month = '01' and c.this_is_cumulate = 'MO' then c.performance_department_name end), '') as name_mo1,
isnull(sum(case when month = '01' and c.this_is_cumulate = 'MO' then score_value end),0) as score_mo1,
isnull(max(case when month = '01' and c.this_is_cumulate = 'MC' then c.performance_department_name end), '') as name_mc1,
isnull(sum(case when month = '01' and c.this_is_cumulate = 'MC' then score_value end),0) as score_mc1,
isnull(max(case when month = '02' and c.this_is_cumulate = 'MO' then c.performance_department_name end), '') as name_mo2,
isnull(sum(case when month = '02' and c.this_is_cumulate = 'MO' then score_value end),0) as score_mo2,
isnull(max(case when month = '02' and c.this_is_cumulate = 'MC' then c.performance_department_name end), '') as name_mc2,
isnull(sum(case when month = '02' and c.this_is_cumulate = 'MC' then score_value end),0) as score_mc2
from
(
select a.rank,
a.month,
a.this_is_cumulate,
a.performance_department_code,
b.performance_department_name,
a.score_value
from hbi_performance_department_rank a
left join hbi_performance_department b
on a.performance_department_code = b.performance_department_code
and a.year = b.year
where a.year = '2007'
and b.upper_performance_department_code = '100000000'
) as c
group by rank
order by rank
위의 쿼리에 의해 구해진 값은 아래와같습니다.
rank |
name_mo1 |
score_mo1 |
name_mc1 |
score_mc1 |
name_mo2 |
score_mo2 |
name_mc2 |
score_mc2 |
1 |
플랜트사업본부 |
94 |
현장 |
162 |
건축사업본부 |
72 |
건축사업본부 |
96 |
2 |
토목사업본부 |
83 |
|
0 |
주택사업본부 |
49 |
플랜트사업본부 |
82 |
3 |
기술지원실 |
78 |
기술지원실 |
69 |
플랜트사업본부 |
46 |
토목사업본부 |
79 |
4 |
기획개발실 |
65 |
토목사업본부 |
61 |
토목사업본부 |
42 |
주택사업본부 |
106 |
5 |
해외사업본부 |
59 |
플랜트사업본부 |
54 |
해외사업본부 |
80 |
|
0 |
6 |
주택사업본부 |
56 |
기획개발실 |
46 |
|
0 |
현장 |
41 |
7 |
건축사업본부 |
39 |
해외사업본부 |
45 |
경영지원실1 |
33 |
기획조정실 |
34 |
8 |
현장 |
31 |
기획조정실 |
14 |
기획개발실 |
15 |
기술지원실 |
23 |
9 |
경영지원실1 |
28 |
경영지원실1 |
13 |
기획조정실 |
8 |
해외사업본부 |
7 |
10 |
기획조정실 |
21 |
주택사업본부 |
4 |
현장 |
5 |
경영지원실1 |
3 |
1월 mo에대한값은 정상입니다.. 나머지 1mc 2mo 2mc에 대해서는
아래쿼리로 확인해봤습니다.
select a.performance_department_code,
b.performance_department_name,
a.this_is_cumulate,
a.rank,
a.score_value
from hbi_performance_department_rank a
left join hbi_performance_department b
on a.performance_department_code = b.performance_department_code
and a.year = b.year
where a.year = '2007'
and a.month= '01'
and b.upper_performance_department_code = '100000000'
and this_is_cumulate = 'mc'
order by rank
performCode.. |
name |
cum |
rank |
score |
100200000 |
건축사업본부 |
MC |
1 |
81 |
101000000 |
현장 |
MC |
1 |
81 |
100900000 |
기술지원실 |
MC |
3 |
69 |
100300000 |
토목사업본부 |
MC |
4 |
61 |
100400000 |
플랜트사업본부 |
MC |
5 |
54 |
100800000 |
기획개발실 |
MC |
6 |
46 |
100500000 |
해외사업본부 |
MC |
7 |
45 |
100600000 |
기획조정실 |
MC |
8 |
14 |
100700000 |
경영지원실1 |
MC |
9 |
13 |
100100000 |
주택사업본부 |
MC |
10 |
4 |
2월 mo 결과
performCode.. |
name |
cum |
rank |
score |
100200000 |
건축사업본부 |
MO |
1 |
72 |
100100000 |
주택사업본부 |
MO |
2 |
49 |
100400000 |
플랜트사업본부 |
MO |
3 |
46 |
100300000 |
토목사업본부 |
MO |
4 |
42 |
100500000 |
해외사업본부 |
MO |
5 |
40 |
100900000 |
기술지원실 |
MO |
5 |
40 |
100700000 |
경영지원실1 |
MO |
7 |
33 |
100800000 |
기획개발실 |
MO |
8 |
15 |
100600000 |
기획조정실 |
MO |
9 |
8 |
101000000 |
현장 |
MO |
10 |
5 |
랭크가 동률일때 저런 현상이 발생합니다
sum을 max함수로 바꾸면 값은 제대로 나오지만 한 항목이 누락되는것은 마찬가지입니다..
이문제를 어떻게 해결해야할까요?
2일동안 고민중인데... 제머리에서는 더이상 나올게 없네요.. 좋은 의견 부탁드리겠습니다.
|