MS ACCESS插入错误,插入到X(…)中,选择…从A中联合选择…从B中。

huangapple go评论63阅读模式
英文:

MS ACCESS Error in insert into X(...) select ... from A union select ... from B

问题

Access 2000 (mdb base).
Stametement:

insert into full_join_DR(y, m, ds, rs, b) 
  select r.y, r.m, d.summa as ds, r.summa as rs, d.summa - r.summa as b 
  from r left join d on r.y = d.y and r.m = d.m 
     union 
  select d.y, d.m, d.summa, r.summa, d.summa - r.summa 
  from d left join r on r.y = d.y and r.m = d.m

> 错误:语法错误

尽管内部的选择语句工作正常

英文:

Access 2000 (mdb base).
Stametement:

insert into full_join_DR(y,m,ds,rs,b) 
  select r.y, r.m, d.summa as ds , r.summa as rs , d.summa - r.summa as b 
  from r left join d on r.y=d.y and r.m=d.m 
     union 
  select d.y, d.m, d.summa, r.summa , d.summa - r.summa 
  from d left join r on r.y=d.y and r.m=d.m

> Error:Syntax error

though inner select statement works correctly

答案1

得分: 0

尝试将联合查询用作子查询:

insert into full_join_DR(y,m,ds,rs,b) 
select t.y, t.m, t.ds, t.rs, t.b
from
  (select r.y, r.m, d.summa as ds, r.summa as rs, d.summa - r.summa as b 
  from r left join d on r.y=d.y and r.m=d.m 
     union 
  select d.y, d.m, d.summa, r.summa, d.summa - r.summa 
  from d left join r on r.y=d.y and r.m=d.m) as t
英文:

Try using the union query as a subquery:

insert into full_join_DR(y,m,ds,rs,b) 
select t.y, t.m, t.ds, t.rs, t.b
from
  (select r.y, r.m, d.summa as ds, r.summa as rs, d.summa - r.summa as b 
  from r left join d on r.y=d.y and r.m=d.m 
     union 
  select d.y, d.m, d.summa, r.summa, d.summa - r.summa 
  from d left join r on r.y=d.y and r.m=d.m) as t

huangapple
  • 本文由 发表于 2023年6月1日 16:32:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380031.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定