나는 다음과 같은 데이터 세트 얻을 수있는 쿼리를 작성하는 올바른 방법을 찾기 위해 노력하고있어 :SQL 서버 SUM은 동일한 출력에 3 개 가지 방법으로 계산
CustName CityID TransactionCount Complete InProc
Hammertown 10001 200 50 150
SportsAuth 10002 10 1 9
"완료"는 작은 또 다른 컬럼 (형식) 미도시 TransactionCount의 집합, TransactionCount의 합이어야 같다 :
having [format]=23
or [format]=25
or [format]=38
or [format]>=400 and [format]<=499
or [format]>=800 and [format]<=899
"에서 InProc"다음 TransactionCount 값의 나머지 부분이어야한다. 지금까지 나는 함께 왔어요 다음
SELECT c.CustName,
t.[City],
sum (t.[TransactionCount]) as InProc
FROM [log].[dbo].[TransactionSummary] t
JOIN [log].[dbo].[Customer] c
on t.CustNo = c.CustNo
and t.City = c.City
and t.subno = c.subno
where t.transactiondate between '6/1/16' and '6/22/16'
group by c.CustName,t.City,t.TransactionCount,[format]
having [format]=23
or [format]=25
or [format]=38
or [format]>=400 and [format]<=499
or [format]>=800 and [format]<=899
을이 현재 다음과 같은 데이터 출력 : 그래서 나만 한 결과를 다시 각 고객 받고 있지 않다되지
CustName CityID InProc
Hammertown 10001 147
Hammertown 10001 1
Hammertown 10001 1
Hammertown 10001 1
SportsAuth 10002 4
SportsAuth 10002 4
SportsAuth 10002 1
을,하지만 난 돈 ' 이 쿼리를 깨지 않고 다른 두 열을 어떻게 추가 할 것인지 알 수 없습니다. 내가 얻을 수있는 도움이 무엇이든간에 크게 감사하겠습니다.
그렇게 다른 질문을 어떤 일에-프로세스? http://stackoverflow.com/questions/37971573/sql-adding-column-a-depend-on-value-in-column-b –
샘플 데이터가 없으면 결과를 이해하는 데 도움이되지 않습니다 –