Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 我是否需要日历来连接access中的表并按月报告_Sql_Ms Access_Inner Join_Outer Join - Fatal编程技术网

Sql 我是否需要日历来连接access中的表并按月报告

Sql 我是否需要日历来连接access中的表并按月报告,sql,ms-access,inner-join,outer-join,Sql,Ms Access,Inner Join,Outer Join,我有3个表需要加入Access。因此,我创建了查询以获取“团队”字段,该字段在“Assoc.NO”上具有[Table A]到[Table C]的内部联接,然后在[Table B]到[Table C]的内部联接也在“Assoc.NO”上 我的问题 我使用基于[表C]和[表a]的查询来获取月份,但如果月份不存在于[表a]中,而仅存在于[表B]中,则我将丢失月份。我是否需要创建一个只有月和年的表并创建一个加入到该表中?我为这篇冗长的文章道歉,但希望提供尽可能多的信息。提前感谢您的帮助 Table A

我有3个表需要加入Access。因此,我创建了查询以获取“团队”字段,该字段在“Assoc.NO”上具有[Table A]到[Table C]的内部联接,然后在[Table B]到[Table C]的内部联接也在“Assoc.NO”上

我的问题

我使用基于[表C]和[表a]的查询来获取月份,但如果月份不存在于[表a]中,而仅存在于[表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       |
我想看到的是:

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           |

您是指表C.团队还是查询C.团队等等?所有对A、B和C的引用都是指您在问题中定义的表。我将得到一个弹出窗口“输入参数值”“SaleB”“我编辑了答案以使用您的表名-看看这是否有帮助。当我在自己的数据库中建模时,它工作得很好。SaleA和SaleB是表A和表B中字段的专有名称吗?Don,可以通过Union从另外两个表中添加数据吗?
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;