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 2005 Forums
 Transact-SQL (2005)
 Query Help!

Author  Topic 

sqldba20
Posting Yak Master

183 Posts

Posted - 2010-12-19 : 15:07:11
Folks:

Based on the below mentioned data I would like to know how my query will be:

Client 'ABC' wants to know if most users have as their last exposure an Start or a Target and from what site it came.
As an output, I would like to see:

Site | Number of users who ended with a Target Flag| Number of users who ended with an Start Flag




Columns: ID, Client, WebAddress, Date, Investment, UserId, Start_Flag, Target_Flag
Data:

1 ABC yahoo 2010-01-01 00:00:00.000 Loan 1 1 0
2 ABC msn 2010-02-01 00:00:00.000 Loan 1 1 0
3 ABC google 2010-03-01 00:00:00.000 Loan 1 0 1
4 ABC yahoo 2010-04-01 00:00:00.000 Loan 1 1 0
5 ABC yahoo 2010-04-02 00:00:00.000 Loan 2 1 0
6 ABC google 2010-03-02 00:00:00.000 Loan 2 0 1
7 ABC msn 2010-01-02 00:00:00.000 Loan 1 0 1
8 ABC bing 2010-01-05 00:00:00.000 Loan 2 0 1
9 ABC bing 2010-01-04 00:00:00.000 Loan 2 0 1
9 ABC yahoo 2010-01-04 00:00:00.000 Loan 1 0 1
10 ABC bing 2010-01-10 00:00:00.000 Loan 1 0 1
11 ABC bing 2010-01-10 00:00:00.000 Loan 2 0 1

Sachin.Nand

2937 Posts

Posted - 2010-12-20 : 04:14:03
select Site,count(Start_Flag),count(Target_Flag) from table
where Start_Flag=1 OR Target_Flag=1
group by Site


PBUH

Go to Top of Page
   

- Advertisement -