sql - Two group by tables stich another table -


i have 3 tables need put together.
first table main transaction table need distinct transaction id numbers , company id. has important keys. transaction ids not unique.
second table has item info linked transaction id numbers not unique , need pull items.
third table has company info has company id.

now i've sold of these first 1 through group id. second through subquery creates unique ids , joins onto first one. issue i'm having third 1 company. cannot seem create query works in above combinations. ideas?

as suggested here code. works that's because company used count doesn't give correct number. how else can company number come out correct?

select     dep.itemidapk,     dep.totalone,     dep.company,     company.vendname,     appd.itemidapk,     appd.itemname (     select         csi.itemidapk,         sum(f.totalone) totalone,         count(f.dimcurrentcompanyid) company     dbo.reportone f (nolock)     inner join dbo.dsaleitem csi (nolock)          on f.dsaleitemid = csi.dsaleitemid      inner join dbo.dimcurrentcompany cv         on f.dimcurrentcompanyid = cv.dimcurrentcompanyid     inner join dbo.dimdate dat         on f.dimdateid = dat.dimdateid     (         dat.date >='2013-01-29 00:00:00.000'         , dat.date <= '2013-01-30 00:00:00.000'     )     group csi.itemidapk ) dep inner join (     select         vend.dimcurrentcompanyid,         vend.name vendname     dbo.dimcurrentcompany vend ) company     on dep.company =  company.dimcurrentcompanyid inner join (     select         c2.itemidapk,         itemname     (         select distinct itemidapk         dbo.dimitem c     ) c1     join dbo.dimitem c2 on c1.itemidapk = c2.itemidapk ) appd     on dep.itemidapk = appd.itemidapk 

for further information output following example, know code executes , companyid incorrect put (count) in make above code execute:

current results:  item number     tls      companyid    company name    item number   item name 111111         300         303         johnson corp       29323      soap   proposed results:   item number     tls      companyid    company name    item number   item name 111111         300         29         johnson corp       29323      soap 


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -