Vb.net 需要Access DB查询帮助

Vb.net 需要Access DB查询帮助,vb.net,ms-access,Vb.net,Ms Access,我有这个访问查询: SELECT trans, sum(total) as tax FROM PURCHASE WHERE matType LIKE 'ad-tax' and trans IN (SELECT trans FROM PURCHASE WHERE matType LIKE 'P-%' Group by trans) group by trans 此查询: SELECT trans, sum(total) as Total FROM PURCHASE WHE

我有这个访问查询:

SELECT trans, sum(total) as tax 
FROM PURCHASE 
WHERE matType LIKE 'ad-tax' 
      and trans IN (SELECT trans FROM PURCHASE WHERE matType LIKE 'P-%' Group by trans) 
group by trans
此查询:

SELECT trans, sum(total) as Total 
FROM PURCHASE 
WHERE matType not LIKE 'ad-tax' 
      and trans IN (SELECT trans FROM PURCHASE WHERE matType LIKE 'P-%' Group by trans)
group by trans
我必须搜索包含正确matType的交易,因为我只需要那些包含税项的交易

交易记录------项目------交易类型------总计

66…………1…………广告税…………9.00

66……….2……….p-944……….60.00

67…………1…………广告税…………6.00

67……….2……….p-903……….40.00

68……….1……….p-998……….29.00

69……….1……….p-921……….10.00

等等

我想知道如何在一个报表中查询:Trans | Total | Tax。这必须是两次约会之间的事,但我自己能弄清楚。我正在从vb.net查询这是否有影响。

可能:

SELECT 'tax', trans, sum(total) as tax FROM PURCHASE 
    WHERE matType LIKE 'ad-tax' and trans 
    IN (SELECT trans FROM PURCHASE WHERE matType LIKE 'P-%' Group by trans) 
    group by trans

UNION ALL

SELECT 'total', trans, sum(total) as Total FROM PURCHASE 
WHERE matType not LIKE 'ad-tax' and trans IN (SELECT trans 
FROM PURCHASE WHERE matType LIKE 'P-%' Group by trans)
 group by trans
我这里没有你的桌子,所以我不能再尝试了

添加:这没有按您喜欢的方式工作,请尝试这样的操作:

SELECT * FROM 
( SELECT trans, sum(total) as tax FROM PURCHASE WHERE matType LIKE 'ad-tax' and trans IN (SELECT trans FROM PURCHASE WHERE matType LIKE 'P-%' Group by trans) group by trans ) [FIRST] 
JOIN 
( SELECT trans, sum(total) as Tot FROM PURCHASE WHERE matType not LIKE 'ad-tax' and trans IN (SELECT trans FROM PURCHASE WHERE matType LIKE 'P-%' Group by trans) group by trans ) [SECOND]
ON [FIRST].[TRANS] = [SECOND].[TRANS]

你没有提出问题,也没有描述你所面临的问题只是不够清楚我想,我只想从有税项的交易中查询trans,total,tax,我不是这方面的专家,我发布的两个查询都符合我的要求,但是我想把它加入到一个声明中,结果是并排的:Trans Total Tax感谢您的快速响应!关闭,而不是并排添加到底部。有什么想法吗?好的,然后选择(第一个选择)加入(第二个选择)。。。在我编辑的答案中类似的东西-这里仍然没有访问权限,但是当我尝试(第一次选择)加入(第二次选择)失败时,想法应该是清楚的。。我读过很多书,尝试过很多方法,但都没有弄明白。。这就是我在这里注册的原因。将您编辑的更改为“左加入”,现在可以使用了。非常感谢,我已经断断续续地处理这个问题很久了。读了很多东西,但我想还是不明白连接。你是在“trans”值上连接两个结果