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 |
|
Auric
Yak Posting Veteran
70 Posts |
Posted - 2006-01-26 : 08:49:23
|
| Hello, I have two tables, one is a "header" and the other is a "Footer" for a customer DB I wrote. The footer has 4 records for each header. I need a field off of the footer to do a 'status count' and I can't get it to work for exampleselect A.Status,count(*) from Header a inner join Footer b on a.CustomerID = b.CustomerID where b.SalesRep='Joe' Basically..I am trying to get an output of Complete 2Cancelled 1 In Progress 3Waiting 1Etc. The problem is the footer table has 4 records for each ... and even if I use a distinct clause... It multiplies the correct result by 4. Select * from users where clue > 0 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-26 : 09:09:10
|
| Pls put the structres of 2 tbls & some sample data + ur expected results |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-01-26 : 11:28:09
|
quote: Originally posted by Auric...It multiplies the correct result by 4...
Divide the count by 4:select A.Status,count(*)/4from Header a inner join Footer bon a.CustomerID = b.CustomerIDwhere b.SalesRep='Joe' CODO ERGO SUM |
 |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2006-01-26 : 11:30:20
|
You obviously didnt come thru the front door did you www.sqlteam.com Take a look at the top article, also read the comments. This should give you what you needAndyEdit: Heres the link to the articlehttp://www.sqlteam.com/item.asp?ItemID=23531Beauty is in the eyes of the beerholder |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-26 : 19:42:29
|
quote: Divide the count by 4:
Getting up on the wrong side of bed ? select a.Status,count(distinct a.CustomerID)from Header a inner join Footer bon a.CustomerID = b.CustomerIDwhere b.SalesRep = 'Joe' ----------------------------------'KH' |
 |
|
|
|
|
|