无法在 MS Access 中跨联合分配别名

Unable to assign aliases across unions in MS Access

我正在尝试从我的数据库中的 table 创建邮件列表,然后在 table 中搜索包含兄弟姐妹信息的列,提取兄弟姐妹信息,搜索那些兄弟姐妹在 table 中,然后将这些兄弟姐妹加入原始邮件列表。

在下面的代码中,我尝试将别名 t1 分配给 select 查询。

SELECT * FROM CountyData AS t1
WHERE dt_dec BETWEEN #05-6-2018# AND #06-06-2018# 
AND RippleImport IS NULL 
AND (Date()-[dob])/365.25 <13.875 

UNION SELECT CountyData.*
FROM CountyData INNER JOIN 

(SELECT TRIM(String_Split([Siblings], 0, ";")) FROM t1 WHERE Siblings IS NOT NULL
UNION
SELECT TRIM(String_Split([Siblings], 1, ";")) FROM t1 WHERE Siblings IS NOT NULL 
UNION
SELECT TRIM(String_Split([Siblings], 2, ";")) FROM t1 WHERE Siblings IS NOT NULL
UNION 
SELECT TRIM(String_Split([Siblings], 3, ";")) FROM t1 WHERE Siblings IS NOT NULL) t2

ON CountyData.[fname]&" "&[lname] = t2.[Expr1000] WHERE RippleImport IS NULL;

当我尝试在第一个联合的另一端调用该别名时,我收到以下错误消息。

'Microsoft Access database engine cannot find the input table or query 't1'. Make sure it exists and that its name is spelled correctly.' 

如何指定一个 table 别名,以便在整个查询过程中识别?

以下应该更正代码中别名的使用:

select t1.* from countydata t1
where t1.dt_dec between #05-6-2018# and #06-06-2018# 
and t1.rippleimport is null 
and (date()-t1.dob)/365.25 <13.875 
union
select t1.* from countydata t1 inner join 
(
    select trim(string_split(t1.siblings, 0, ";")) as sib from countydata t1 where t1.siblings is not null
    union
    select trim(string_split(t1.siblings, 1, ";")) as sib from countydata t1 where t1.siblings is not null 
    union
    select trim(string_split(t1.siblings, 2, ";")) as sib from countydata t1 where t1.siblings is not null
    union 
    select trim(string_split(t1.siblings, 3, ";")) as sib from countydata t1 where t1.siblings is not null
) t2 on t1.fname & " " & t1.lname = t2.sib 
where t1.rippleimport is null;

但是,使用计算的连接条件可能更有效,例如:

select t1.* from countydata t1
where t1.dt_dec between #05-6-2018# and #06-06-2018# 
and t1.rippleimport is null 
and (date()-t1.dob)/365.25 <13.875 
union
select t1.* 
from countydata t1 inner join 
(
    select t.siblings as s from countydata t where t.siblings is not null
) 
t2 on 
(
    t1.fname & " " & t1.lname = trim(string_split(t2.s, 0, ";")) or
    t1.fname & " " & t1.lname = trim(string_split(t2.s, 1, ";")) or
    t1.fname & " " & t1.lname = trim(string_split(t2.s, 2, ";")) or
    t1.fname & " " & t1.lname = trim(string_split(t2.s, 3, ";"))
)
where t1.rippleimport is null;

以上内容完全未经测试。