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 |
|
windtr
Starting Member
2 Posts |
Posted - 2012-04-24 : 13:43:39
|
| Hello, I want to add contitional logic into my select statement but not sure of the syntax and would appreciate any help.The below code is what i am trying but obviously the syntax is wrongselect count(distinct email) where new='Y' as new, count(distinct email),(count(distinct email) where new='Y')/count(distinct email) as new_rate |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-04-24 : 14:24:26
|
If you post the information on your tables with some sample input data and the output you expect to get, people on the forum would be in a better position to help. See here if you need some help posting: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxI am guessing you need something like this:SELECT COUNT(DISTINCT email) AS TotalEmails, COUNT(DISTINCT CASE WHEN new = 'Y' THEN email END) AS NewEmails, 1.0* COUNT(DISTINCT CASE WHEN new = 'Y' THEN email END)/COUNT(DISTINCT email)FROM YourTable |
 |
|
|
windtr
Starting Member
2 Posts |
Posted - 2012-04-24 : 14:32:07
|
| thank you so much! that is exactly what i needed. |
 |
|
|
|
|
|