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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Problem with count result in a view

Author  Topic 

jl45
Starting Member

4 Posts

Posted - 2006-10-20 : 09:41:16
I have the following SQL

SELECT     
Scheme,
Application_Date,
LTVGroup,
LTVSort,
SUM(LoanGrossAmount) AS ApplicationValues,
COUNT(ApplicationRef) AS ApplicationCount,
Rate,
ProductCode,
ApplicationRef
FROM reporting..AppsInLTV
GROUP BY Scheme, Application_Date, LTVGroup, LTVSort, Rate, ProductCode,ApplicationRef


which produces the following for appref = XXXXXXXX

SC,2006-10-19 00:00:00.000,80.01%-85%,4,501247.00,1,5.49%,SC3,XXXXXXXX
SC,2006-10-19 00:00:00.000,80.01%-85%,4,501247.00,1,5.99%,SC5,XXXXXXXX


Because application 'XXXXXXXX'is split over 2 products there are 2 rows returned which is fine but I would like the Application count field to reflect this by dividing the result by the number of times the app number appears (eg for this example 2 but it could be 1,2,3 or 4 products) is there any way of doing this so I can get the result to be

SC,2006-10-19 00:00:00.000,80.01%-85%,4,501247.00,0.5,5.49%,SC3,XXXXXXXX
SC,2006-10-19 00:00:00.000,80.01%-85%,4,501247.00,0.5,5.99%,SC5,XXXXXXXX


so if it appear once divide by 1, if it apppears twice divide by 2, ..., if it appears 4 times then divide by 4.

Hope anyone can help.

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-20 : 10:57:21
Well it really doesn't appear more than once based on your grouping. You need to reduce your groupinng to dount what you want, then divide by COUNT(*)



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -