如何使用主表和详细信息表值进行查询 [英] How to get query with master and detail table values

查看:79
本文介绍了如何使用主表和详细信息表值进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在billno和item的详细信息表中有4条记录。并且在billno主表中有一条记录。



详情有净值,税收和税率。

和netpay(净+税)在主表中



我需要明智地查询netvalue,taxp,taxval和netpay税率



我的查询在netpay中给出了多重价值



提前致谢。



我尝试过:



 选择 sum(a.netvalue),总和(a.taxvalue),a.taxp,b.netpay 来自详细信息表a,mastertable b 
其中 a.billno = b.billno group by a.taxp,b.netpay

解决方案

您需要将 SUM()部分与其他字段分开。 />
您可以使用a.taxp,b.netpay的查询,然后使用 UNION 进行SUM()查询rwards。

Hi,
I have 4 records in detail table with billno and item. And have one record in master table with billno.

Detail has netvalue ,taxper and taxvalue.
And netpay(net+tax) only in master table

I need query netvalue,taxp,taxval and netpay tax percentage wise

My query gives multiple value in netpay

Thanks in advance.

What I have tried:

select sum(a.netvalue),sum(a.taxvalue),a.taxp,b.netpay from detailtable a,mastertable b
where a.billno=b.billno group by a.taxp,b.netpay

解决方案

You need to keep the SUM() part separate of the other fields.
You could use a query for the a.taxp, b.netpay and then use UNION for the SUM() query afterwards.


这篇关于如何使用主表和详细信息表值进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆