2016-11-07 2 views
2

Access에 가입해야하는 테이블이 3 개 필요합니다. 그래서 "Assoc. NO"의 [Table A]와 [Table C]의 내부 조인을 가진 "팀"필드를 얻고 "Assoc."의 [Table C]의 또 다른 테이블을 가져 오는 쿼리를 만들었습니다. NO].액세스 테이블을 조인하고 월별 보고서를 작성하려면 캘린더가 필요합니까?

내 문제

나는 달을 얻기 위해 [표 C]와 [표 A]를 기반으로 쿼리를 사용하지만, 나는이 실종 개월 그들은 [표 A에 존재하지 않은 경우 ] 그리고 오직 [Table B] 만 있습니다. 수개월의 테이블을 만들고 그것에 가입해야합니까? 긴 게시물에 사과드립니다. 가능하면 많은 정보를 제공하고 싶습니다. 미리 도움을 청하십시오. .

Table A 
|Name   | Assoc. NO |month|Year|Product|SaleA| 
|John Smith | 1  |Jan |2016|Apple |$10 | 
|John Smith | 1  |Jan |2016|Pear |$5 | 
|John Smith | 1  |Feb |2016|Apple |$10 | 
|George Martin| 2  |Feb |2016|Apple |$10 | 
|George Martin| 2  |Feb |2016|Apple |$10 | 
|George Martin| 2  |Feb |2016|Pear |$5 | 


Table B 
|Name   | Assoc. NO |month|Year|Service |SaleB| 
|John Smith | 1  |Jan |2016|oil change|$25 | 
|George Martin| 2  |Jan |2016|oil change|$25 | 
|Mark James | 3  |Feb |2016|oil change|$25 | 
|Mark James | 3  |Mar |2016|oil change|$25 | 
|George Martin| 2  |Mar |2016|oil change|$25 | 

Table C 
|Team |Name   | Assoc. NO | 
|Team A |John Smith | 1  | 
|Team B |George Martin| 2  | 
|Team B |Mark James | 3  | 
내가보고 싶은 것이 6,

는 다음과 같습니다 : 당신이 그렇게 표 C.Team 또는 쿼리 C. 팀과에

Query 
|Team |Name   | Month |Sale |SaleB|SUM(SaleA,SaleB)| 
|-------|-------------|--------|-----|-----|----------------| 
|Team A |John Smith | Jan | $15 | $25 | $40   | 
|Team A |John Smith | Feb | $10 | $0 | $10   | 
|Team B |George Martin| Jan | $0 | $25 | $25   | 
|Team B |George Martin| Feb | $25 | $0 | $25   | 
|Team B |George Martin| Mar | $0 | $25 | $25   | 
|Team C |Mark James | Feb | $0 | $25 | $25   | 
|Team C |Mark James | Feb | $0 | $25 | $25   | 

답변

0
SELECT [Table C].Team, [Table C].Name, [Table C].[Assoc No], Month, Sum(T.SaleA) AS TotA, Sum(T.SaleB) AS TotB, [TotA]+[TotB] AS Total 
FROM 

(select [Assoc no], Month, SaleA, 0 as SaleB from [Table A] 
UNION ALL select [Assoc No], Month, 0, Saleb from [Table B]) AS T 

INNER JOIN [Table C] ON T.[Assoc No]= [Table C].[Assoc No] 
GROUP BY [Table C].Team, [Table C].Name, Table C].[Assoc No], T.Month; 
+0

을 언급하고 있는가? – Angel

+0

A, B 및 C에 대한 모든 참조는 해당 질문에서 정의한 테이블에 대한 것입니다. –

+0

"매개 변수 값 입력" "SaleB"팝업이 나타납니다 – Angel