Microsoft Access 中的联合

Union in Microsoft Access

我有一个链接访问数据库,如下所示:

country year numTest AF 1990 30 AF 1991 45 AF 1992 50 AF 1993 55 AF 1994 50 BZ 1990 409 BZ 1991 509 BZ 1992 405 BZ 1993 874 CO 1990 0 CO 1991 0 CO 1992 0

我创建的第一个查询是将每个国家/地区的这些年汇总在一起(名为 testPerformed)

SELECT TB_basicInfo.country, Sum(TB_hivTest.hivtest) AS SumOfhivtest
FROM TB_hivTest INNER JOIN TB_basicInfo ON TB_hivTest.ID = TB_basicInfo.ID
GROUP BY TB_basicInfo.country;

但现在我想排除总和小于 1 的任何国家。所以我创建了一个新查询,如下所示:(named testPerformed > 1)

SELECT testPerformed.country, testPerformed.SumOfhivtest
FROM testPerformed
WHERE ((testPerformed.SumOfhivtest)>1);

所以 CO 自然会被排除在外,如果我单独运行每个查询,这将正常工作。但是有没有一种方法可以将其组合成一个查询。

我累了:

SELECT TB_basicInfo.country, Sum(TB_hivTest.hivtest) AS SumOfhivtest
FROM TB_hivTest INNER JOIN TB_basicInfo ON TB_hivTest.ID = TB_basicInfo.ID
GROUP BY TB_basicInfo.country
UNION
SELECT TB_basicInfo.country, SumOfhivtest
WHERE SumOfhivtest > 0;

但访问不喜欢此查询,因为它提示我输入 SumOfhivtest

如果我正确理解您的尝试,请尝试以下操作:

SELECT TB_basicInfo.country, Sum(TB_hivTest.hivtest) AS SumOfhivtest
FROM TB_hivTest INNER JOIN TB_basicInfo ON TB_hivTest.ID = TB_basicInfo.ID
GROUP BY TB_basicInfo.country
HAVING Sum(TB_hivTest.hivtest) > 0;