【问题标题】:Inner join with index query MS Access使用索引查询 MS Access 进行内部联接
【发布时间】:2013-01-07 15:49:06
【问题描述】:

我有两张桌子

客户

CustomerID   name  x2       x3 
--------------------------------
14tr          Joe   att2   att3
11ty          Jack  att2   att3

存款

Depositid CustomerID quantity date      att3 att4
--------------------------------------------------
13           14tr      100   12-12-12     5    6
14           14tr      200   12-13-12     8    1
15           14tr      140   12-16-12     9    6
16           11ty      10    12-19-12     1    6
17           11ty      20    12-19-12     1    1
18           11ty      114   12-21-12     1    6

我想要以下结果:

结果

No   name    quantity     date  att3 att4    x2     x3
-----------------------------------------------------------------------
1    Joe       100   12-12-12     5    6    att2  att3
1    Joe       200   12-13-12     8    1    att2  att3  
1    Joe       140   12-16-12     9    6    att2  att3
2    Jack       10   12-19-12     1    6    att2  att3
2    Jack       20   12-19-12     1    1    att2  att3
2    Jack      114   12-21-12     1    6    att2  att3

我正在这样做

SELECT
  b.name, 
  a.quantity, 
  a.date, 
  a.att3,
  a.att4, 
  b.x2, 
  b.x3
FROM
  Deposit a INNER JOIN Customer b
  ON a.CustomerID = b.CustomerID;

如何获得示例中每个不同客户的编号列计数器?

有没有更好的方法来显示这两个表之间的内连接?

【问题讨论】:

  • 什么版本的ms访问?
  • 是否可以先使用 Access 2007,然后再使用 2010?还是兼容性问题?
  • 如何获得 No 列?
  • 听起来你想通过sql生成No.列,试试这个ehow.com/how_5976723_do-number-records-access-query_.html
  • 为什么 Joe 编号为“1”,您认为“1”来自哪里?

标签: sql ms-access inner-join


【解决方案1】:

你可以:

SELECT DCount("*","Customer","CustomerID <='" & b.CustomerID & "'") AS Ct, 
b.name, 
a.quantity, 
a.Date, 
a.att3, 
a.att4, 
b.x2, 
b.x3
FROM Deposit AS a 
INNER JOIN Customer AS b ON a.CustomerID = b.CustomerID
ORDER BY b.CustomerID;

结果:

Ct  name    quantity    Date    att3  att4  x2      x3
1   Jack    114     21/12/2012  1       6   att2    att3
1   Jack    20      19/12/2012  1       1   att2    att3
1   Jack    10      19/12/2012  1       6   att2    att3
2   Joe     140     16/12/2012  9       6   att2    att3
2   Joe     200     13/12/2012  8       1   att2    att3
2   Joe     100     12/12/2012  5       6   att2    att3

【讨论】:

  • 当我执行它时,我将计数器设置为 2 而不是 1,如何将计数器设置为 1? ,我用SELECT DCount("*","Customer","CustomerID &lt;= " &amp; [b.CustomerID ])
  • 哦,我把它改成了SELECT DCount("*","Customer","CustomerID &lt; " &amp; [b.CustomerID ]),它工作了
  • 在这种情况下,您必须有一个客户没有出现在您的存款表中,但确实出现在您的客户表中。最好创建一个查询来获取一组有存款的客户并将其用于您的 DCount。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-17
  • 1970-01-01
  • 2016-01-18
  • 1970-01-01
  • 2014-12-16
  • 2021-05-29
  • 1970-01-01
相关资源
最近更新 更多