我自己加入了一个查询,我的代码在 ase isql 上运行正常。但是,当我想在 access 2007 中使用它时,我收到以下错误“派生表表达式缺少相关名称。检查参考手册中的派生表语法”原始代码执行以下操作:
select TT.name, TT.lastname, max(amount) as maxsalecurrentweek
from sales
inner join
(select s1.id_employee, e.name, e.lastname, e.address, e.age, e.id_employee
from employee e
join sales s1 on e.id_emplyoee = s1.id_employee
where
some conditions here) as TT
on sales.id_employee = TT.id_employee
group by
TT.name, TT.lastname
在原始代码中,我在内部查询中加入了更多表以及一些 where 条件。但是上面的代码应该说明我做了什么。
看起来我自己加入表格的方式是访问问题。有谁知道正确的语法是什么?或者,如果 access/JET/ACE 支持这种内部连接,它自己的方法?
这是原始代码:
select max(tort140.BEL_GRLAG_AP) as MaxPensjonGr, TT.IDE_KUNDE_PRSNR,
TT.DAT_KUNDE_FOEDT_NUM, TT.AvtaleID, TT.Orgnr, TT.Arbeidsgiver,
TT.Sivilstatus, TT.Polisestatus, TT.Årslønn from tort140
inner join
(select distinct tort128.NUM_AVTALE_ID as AvtaleID,
tort009.IDE_ARBGIV_NR as Orgnr,
tort134.NVN_ARBGIV as Arbeidsgiver,
tort127.DAT_KUNDE_FOEDT_NUM as DAT_KUNDE_FOEDT_NUM,
tort127.IDE_KUNDE_PRSNR as IDE_KUNDE_PRSNR,
tort001.STA_SIVILSTATUS as Sivilstatus,
tort128.typ_status as Polisestatus,
tort128.rte_polisegrad as Polisegrad,
tort140.BEL_LOENN_AAR as Årslønn,
tort138.IDE_SEKV_TORT138"
from tort140 left join (tort138 join (tort128 join (tort134 join (tort009 join (tort001 join tort127
on tort127.DAT_KUNDE_FOEDT_NUM=tort001.DAT_KUNDE_FOEDT_NUM and tort127.IDE_KUNDE_PRSNR=tort001.IDE_KUNDE_PRSNR)
on tort127.DAT_KUNDE_FOEDT_NUM=tort009.DAT_KUNDE_FOEDT_NUM and tort127.IDE_KUNDE_PRSNR=tort009.IDE_KUNDE_PRSNR)
on tort009.IDE_ARBGIV_NR=tort134.IDE_ARBGIV_NR)
on tort128.IDE_SEKV_TORT127 = tort127.IDE_SEKV_TORT127)
on tort128.IDE_SEKV_TORT128 = tort138.IDE_SEKV_TORT128)
on tort140.IDE_SEKV_TORT138 = tort138.IDE_SEKV_TORT138)
where tort128.NUM_AVTALE_ID = '102356' and tort128.DAT_GYLDIG_FOM <= 20120101
and (tort128.DAT_GYLDIG_TOM >= 19520000 or tort128.DAT_GYLDIG_TOM is null
and tort128.DAT_HISTORISK is null and tort128.TYP_STATUS= 'akt' and tort127.DAT_KUNDE_FOEDT_NUM >= 19650000
and tort127.DAT_KUNDE_FOEDT_NUM <= 19550000 and tort127.DAT_TERMINERT is null and tort127.DAT_REGISTRERT<= 19550000
and tort009.DAT_SLUTT is null and tort134.DAT_HISTORISK is null
and tort138.DAT_AKSJON=(select max(p.DAT_AKSJON) from tort138 p where 1=1 and p.IDE_SEKV_TORT128=tort128.IDE_SEKV_TORT128)
) as TT
on TT.IDE_SEKV_TORT138 = tort140.IDE_SEKV_TORT138
Group by TT.IDE_KUNDE_PRSNR, TT.DAT_KUNDE_FOEDT_NUM, TT.AvtaleID, TT.Orgnr,
TT.Arbeidsgiver, TT.Sivilstatus, TT.Polisestatus, TT.Årslønn from tort140
内部查询在 access 2007 上运行没有任何问题。编写内部联接时收到错误消息。你认为这个查询可以适合访问吗?我是否缺少一些刹车或其他东西?