本文介绍了Sql查询给出多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我的表中只有4或5条记录,但下面的查询显示12或13条记录,它显示3条记录3次等等



In my DB there are only 4 or5 records in my tables but the query below is showing 12 or 13 records it''s showing 1 record 3 times and so on

select A.Date,OwnerName,Rate,Weight,PreviousAmount from Company F inner join TrashSaleOrders C on F.Companyid=C.Companyid  inner join Accounts A on C.Companyid=A.Companyid





I想要显示订购人的姓名(OwnerName)和Orderdetails(费率,重量)和他之前的金额(PreviousAmount)(如果有的话)。表公司包含(Companyid,OwnerName)表TrashSaleOrders包含(Companyid,Date,Weight,Rate)表帐户包含(Accountid,Companyid,Date,PreviousAmount,Payment,AmountLeft)



I want to display Name (OwnerName) of person who ordered and Orderdetails (Rate,Weight) and his previous amount (PreviousAmount) if any. Table Company contains (Companyid,OwnerName) Table TrashSaleOrders contains (Companyid,Date,Weight,Rate) Table Accounts contains (Accountid,Companyid,Date,PreviousAmount,Payment,AmountLeft)

推荐答案


select A.Date,OwnerName,Sum(Rate),Sum(Weight),sm(PreviousAmount)
from Company F 
inner join TrashSaleOrders C on F.Companyid=C.Companyid  
inner join Accounts A on C.Companyid=A.Companyid and A.Date = C.Date
Group by A.Date, OwnerName



快乐编码!

:)


Happy Coding!
:)


这篇关于Sql查询给出多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 00:47