如何在MS Access中使用UNION联接两个不同的表

时间:2019-03-19 06:24:47

标签: sql ms-access

我有以下查询

Select sum (ABC) as ecr from table1 
Where a<>'y' or b is null and c<>'g'

Union all

Select sum(bcd) as ech from table2 

注意:我在一栏下得到结果,但我想在两栏下显示

3 个答案:

答案 0 :(得分:0)

请尝试这个。

SELECT sum (A.ABC) as ecr,SUM(B.bcd) as ech 
FROM table1 AS A
LEFT JOIN table2 AS B
ON B.Id = A.Id
Where A.a<>'y' or A.b is null and A.c<>'g'

答案 1 :(得分:0)

我认为您只需要一个cross join

Select sum(ABC) as ecr,
       sum(bcd) as ech
  from table1 t1
 cross join table2
 Where t1.a <> 'y'
    or t1.b is null
   and t1.c <> 'g'

答案 2 :(得分:0)

在MS Access中,您将,用于CROSS JOIN

select t1.ecr, t2.ech
from (select sum(ABC) as ecr
      from table1 
      where a <> 'y' or b is null and c <> 'g'
     ) t1,
     (select sum(bcd) as ech
      from table2 
     ) t2;

在任何其他数据库中,您将使用CROSS JOIN