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
 Transact-SQL (2000)
 Trouble counting

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-12-14 : 10:53:51
Cam writes "I have a table that looks something like this:


date email
----- ----
aaa 1-Jan
bbb 5-Jan
aaa 3-Feb
ccc 6-Feb



What I'm trying to do is count the number of new, unique emails that occured in each month. In my example - I'm looking to see that there were 2 in Jan and 1 in Feb (since the Feb 3 'aaa' had already been counted).

Can anyone help me wrap my noodle around this? Thanks in advance,


Cam"

efelito
Constraint Violating Yak Guru

478 Posts

Posted - 2001-12-14 : 11:35:44
Something like this should do the trick

select cast(datepart(month, t1.date) as char(2)) + '/' + cast(datepart(year, t1.date) as char(4)), count(t1.email)
from (
select min(date) as date, email
from tablename
group by email
) as t1
group by cast(datepart(month, t1.date) as char(2)) + '/' + cast(datepart(year, t1.date) as char(4))

Jeff Banschbach
Consultant, MCDBA
Go to Top of Page
   

- Advertisement -