Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
tech
Starting Member
32 Posts |
Posted - 2011-03-20 : 16:46:40
|
| OK, I have 4 tables:Users (has distributorLinkID)DistributorsCompanies LinkDistCompanies (Joining table for the above 2)A user joins and has an ID linking to LinkDistCompaniesA User also collects points (a table holds this info per user)how can I calculate the total where for each distributor and for all companies for a distributor, all the user points are added up for that distributor (for each company)does this make sense?So user:bob is with distributor1, company 2bill is with distributor2, company 1jane is with distrubtor1, company 2I want to show the total for distributor1 and distributor2 by summing up the points/score for that distributor (for each company associated with that distributor)thanks |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-03-21 : 05:54:01
|
| please come up with sample data and the required output in light of that data, in order to avoid guessing!CheersMIK |
 |
|
|
tech
Starting Member
32 Posts |
Posted - 2011-03-21 : 13:07:45
|
| its pretty simple. sample data as supplied as output is just a count of numbers.Users table:UIDNameCompanyID (FK NULL)DistributorLinkID (FK NULL)UserScoresID int PKUserID int FKScore intCompany Table:ID int PKCompanyNameDistributor Table:DistributorID int PKDistributorName nvarchar(50)DistributorCompanies Table:DCID int PKCompanyNameDCLink Table:ID PK intDistributorID INT FKDistributorCompanyID INT FK |
 |
|
|
tech
Starting Member
32 Posts |
Posted - 2011-03-21 : 21:02:15
|
| anyone? should be simple but can't think in a simple way!let me maybe try and make it clearer.a user can be associated with a company OR distributor and its companies.a user has a totalpoints table.If a user is for a distributor, then I want to calculate the total points for each company which belongs to a distributor.so distributor1 may have 5 companies and 10 users under itdist2 may have 3 companies and 1 user under itso a given distributor (passing an ID to it), I want to calculate the SUM of all the user points for each company that is associated with a distributor.makes sense? :-) |
 |
|
|
|
|
|