June 16, 2003 at 1:19 am
I have a table "visits":
salesperson customerID visitDate
----------- ---------- ---------
s01 c01 2002-05-27
s01 c01 2003-05-11
s01 c01 2003-06-13
s01 c03 2003-06-13
s02 NULL NULL
s03 c02 2003-04-12
Would like to count the number of visits each salesperson has made in a specific year and month (2003, May). Like this:
salesperson noOfVisits
---------- ----------
s01 1
s02 0
so3 0
However, i don't know how to get a 0 for salesperson s03...whereas s02 gets 0. Please help me, i know this is probably easy for all of you but i'm really new and confused.
thanks in advance
Lis
June 16, 2003 at 1:47 am
Lis,
Something like this should work.
select salesperson,
sum(case when month(visitDate) = 5 and year(visitDate) = 2003 then 1 else 0 end) as noOfVisits
from visits
group by salesperson
June 16, 2003 at 1:54 am
JteL,
yes it did! Thank you so much!
Lis
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply