运行查询的 MS Access 帮助
Posted
技术标签:
【中文标题】运行查询的 MS Access 帮助【英文标题】:MS Access Help to run a query 【发布时间】:2019-01-24 10:25:15 【问题描述】:我有两张表如下。
我想获取所有活跃的会员,付款期=每两周一次,以及每个会员在特定年份和月份的相应储蓄记录。请注意,某些成员可能没有给定年份和月份的储蓄记录。 我写了一个查询,但它没有返回在储蓄表中没有储蓄记录的成员。
SELECT Member.memberID As [ID],Member.firstName AS [First Name],
Member.lastName AS [Last Name], Member.paymentPeriod AS [Payment Period],
Savings.savingId AS [Savings Id], Savings.enteredAmount AS [Amount]
FROM Member
LEFT JOIN Savings ON Member.memberID = Savings.memberId
WHERE Member.isActive = 'Active' AND Member.paymentPeriod = 'Fortnightly'
AND Year(Savings.enteredDate)=2019 AND Month(Savings.enteredDate) = 1;
【问题讨论】:
【参考方案1】:将SAVINGS
条件从WHERE
移动到ON
以获得真正的LEFT JOIN
结果:
SELECT Member.memberID As [ID],Member.firstName AS [First Name],
Member.lastName AS [Last Name], Member.paymentPeriod AS [Payment Period],
Savings.savingId AS [Savings Id], Savings.enteredAmount AS [Amount]
FROM Member
LEFT JOIN Savings ON Member.memberID = Savings.memberId
AND Year(Savings.enteredDate)=2019 AND Month(Savings.enteredDate) = 1
WHERE Member.isActive = 'Active' AND Member.paymentPeriod = 'Fortnightly';
(使用WHERE
子句中的这些条件,您将获得常规的INNER JOIN
结果。)
编辑:尝试避免“Join expression not supported error”:
SELECT Member.memberID As [ID],Member.firstName AS [First Name],
Member.lastName AS [Last Name], Member.paymentPeriod AS [Payment Period],
Savings.savingId AS [Savings Id], Savings.enteredAmount AS [Amount]
FROM Member
LEFT JOIN Savings ON Member.memberID = Savings.memberId
WHERE Member.isActive = 'Active' AND Member.paymentPeriod = 'Fortnightly'
AND (Year(Savings.enteredDate)=2019 or Year(Savings.enteredDate) IS NULL)
AND (Month(Savings.enteredDate) = 1 or Month(Savings.enteredDate) IS NULL);
【讨论】:
我试过了,但我得到了 Join expression not supported 错误:(以上是关于运行查询的 MS Access 帮助的主要内容,如果未能解决你的问题,请参考以下文章