|
|
Question : Problem with DISTINCT COUNT query
|
|
I am trying to count all the "New Consumer" that have been contacted within a time frame. The query below seems to count the amount of contacts for New Consumers within a time frame. For example, for the month of October, I know that I have contacted 9 new consumer, but the query results gives me 18 because that's the number of New Consumer contacts/calls made within that same month. What am I missing in my query?
SELECT DISTINCT COUNT(c.consumerid) AS [New Consumers] FROM c_calls AS c LEFT JOIN c_contacts AS a ON a.consumer_id=c.consumerid WHERE a.c_status = 1 and c.c_calldate Between Forms!frmStartEndDate!StartDate And Forms!frmStartEndDate!EndDate;
Tip: a.c_status = 1 is New Consumers Tip 2: I have already tried switching DISTINCT COUNT(a.consumer_id) -- still got the same results
Thanks in advance for your help
|
Answer : Problem with DISTINCT COUNT query
|
|
And of course - based largely on the question title... If it's an actual count of the distinct customers you want (supported also by Angel's supposition when he suggested the T-SQL syntax COUNT(DISTINCT c.consumerid)
SELECT COUNT(*) FROM ( SELECT DISTINCT c.consumerid AS [New Consumers] FROM c_calls AS c LEFT JOIN c_contacts AS a ON a.consumer_id=c.consumerid WHERE a.c_status = 1 and c.c_calldate Between Forms!frmStartEndDate!StartDate And Forms!frmStartEndDate!EndDate )
Ray - I'm not sure what you're saying re the Selecting and On Clauses. The order in the On clause itself shouldn't matter... just the directionality of the Join if Outer.
|
|
|
|