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
 Leads by rating Breakdown

Author  Topic 

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-05-05 : 07:56:13
i currently work with a microsoft crm which works over an sql database. however i need to pull out some reports but i am having a hard time.

Sales Person Leadname adress rating
------------ -------- ----- ------
john doe mary doe 12 1st street hot
jane doe example 21 mary st cool

how do i pull out the total of hot or cold ratings per sales person and present all the information on one table.
Please help



Melvin Felicien
IT Manager
DCG Properties Limited

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-05 : 08:03:08
[code]
select [Sales Person],
total_hot = sum(case when rating = 'hot' then 1 else 0 end),
total_cool = sum(case when rating = 'cool' then 1 else 0 end)
from table
group by [Sales Person]
[/code]


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-05 : 08:07:05
Otherwise post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-05-05 : 08:13:43
Thank you so much. this is exactly what i am looking for.
thank you guys for the quick response.

one more question. if i were to want to add the total of all the ratings per sales person eg sum of hot+cool and total them. how do i achieve this.

Melvin Felicien
IT Manager
DCG Properties Limited
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-05 : 08:18:29
[code]
select [Sales Person],
total_hot = sum(case when rating = 'hot' then 1 else 0 end),
total_cool = sum(case when rating = 'cool' then 1 else 0 end),
total_rating = count(*)
from table
group by [Sales Person][/code]


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-05 : 08:22:15
Also Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2007-05-05 : 08:25:14
This works perfectly. Thank you much

Melvin Felicien
IT Manager
DCG Properties Limited
Go to Top of Page
   

- Advertisement -