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
 General SQL Server Forums
 New to SQL Server Programming
 Count rows dependng on conditions on previous rows

Author  Topic 

adamsm28
Starting Member

5 Posts

Posted - 2010-12-30 : 05:12:04
Hi,

I have a sales table as follows:

PK CustomerID Outcome SalesPerson
1 123 No Answer Fred Smith
2 123 Info Given Fred Smith
3 124 Busy John Jones
4 123 Sale Fred Smith
5 124 Sale John Jones

and I need to work out how many sales were first conversions i.e. those with a sales outcome of Sale but with the condition that the sales person hasn't already spoken with a customer. So in the table, row 5 is a first conversion but row 4 isn't as the sales guy has already spoken to the customer in row 2.

I need to count these rows by agent so the return count here would be 1 John Jones and 0 Fred Smith.

I've spent some time trying to code this, but it is more difficult (to me!) than it first appears.

Any pointers would be much appreciated.

Thanks!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-30 : 06:06:26
So Outcome='Busy' in row 3 is to ignore?
Are there more conditions to decide if it is a "first conversion"?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

adamsm28
Starting Member

5 Posts

Posted - 2010-12-30 : 06:32:59
Hi - yes that is correct. There are other conditions such as No Answer, Answer Machine etc. There are only 5 or 6 of these and they will be a fixed list, so we could hard code them into a query.
Go to Top of Page
   

- Advertisement -