이렇게 각 각의 조회문으로 조회를 하면 5, 2가 나옵니다.
그런데 아래 그림처럼 조인을 하여 두개가 같이 나오게 하였더니
이렇게 10개 10개가 나옵니다..
10개 10개로 나오는 이유는 ..
송재주의 회원번호의 개수가 BROD는 5개 NEWS는 2개 이기 때문입니다.,,
2,5가 나와야하는데 방법이 없을까요 ?
이렇게 각 각의 조회문으로 조회를 하면 5, 2가 나옵니다.
그런데 아래 그림처럼 조인을 하여 두개가 같이 나오게 하였더니
이렇게 10개 10개가 나옵니다..
10개 10개로 나오는 이유는 ..
송재주의 회원번호의 개수가 BROD는 5개 NEWS는 2개 이기 때문입니다.,,
2,5가 나와야하는데 방법이 없을까요 ?
Sum 이 어떤 Sum 을 말씀하시는지 모르겠네요..
글만 봐서는요...
일단 결과물만 나오게끔 쿼리했습니다.
---- 쿼리 시작 ----
With Tbl As
(
Select 'T00000038804' As sup_no, 'C2015020018' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038804' As sup_no, 'C2015020017' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038805' As sup_no, 'C2015020018' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038805' As sup_no, 'C2015020017' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038806' As sup_no, 'C2015020018' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038806' As sup_no, 'C2015020017' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038807' As sup_no, 'C2015020018' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038807' As sup_no, 'C2015020017' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038808' As sup_no, 'C2015020018' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT Union All
Select 'T00000038808' As sup_no, 'C2015020017' As RDNO, 'TV국' As DEPTNAME_KO , 'TV_제작1부' As DEPTNAME_KO2 , '송재주' As HNAME , 1.0 As ACC_COUNT , 1 As BU_CNT
)
Select
Sum(a.sup_no) As sup_no
,Sum(a.RDNO ) As RDNO
From
(
Select
Top 1 Count(a.sup_no) As sup_no
,0 AS RDNO
From
(
Select
a.sup_no As sup_no
From Tbl a
Group By a.sup_no
) a
Union All
Select
Top 1 0 As sup_no
,Count(a.RDNO) AS RDNO
From
(
Select
a.RDNO As RDNO
From Tbl a
Group By a.RDNO
) a
) a