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
 General SQL Server Forums
 New to SQL Server Programming
 Counting tickets per customer per month (basic)

Author  Topic 

urmas80
Starting Member

20 Posts

Posted - 2013-02-22 : 04:11:06
Hi All, I believe, I have a basic question:
Trying to count tickets per client per month, expected result:

January 3 Customer 1
January 15 Customer 2
January 1 Customer 3
February 15 Customer 1
February 10 Customer 2
February 2 Customer 3

But instead i just getting :

January 1 Customer 1
January 1 Customer 2
January 1 Customer 3
February 1 Customer 1
February 1 Customer 2
February 1 Customer 3

This is my query:

SELECT DATENAME(MONTH,datetimeOpened)AS PerMonth,
COUNT(fldIWfId) AS Tickets,
OrganizationfldName AS Customer
FROM mytable
WHERE datetimeOpened > dateadd(year, -1, GETDATE())
GROUP by OrganizationfldName, fldIWfId, datetimeOpened
Order BY PerMonth desc


Thank you in advance,

U

Abu-Dina
Posting Yak Master

206 Posts

Posted - 2013-02-22 : 04:22:52
[code]SELECT DATENAME(MONTH,datetimeOpened)AS PerMonth,
COUNT(fldIWfId) AS Tickets,
OrganizationfldName AS Customer
FROM mytable
WHERE datetimeOpened > dateadd(year, -1, GETDATE())
GROUP by DATENAME(MONTH,datetimeOpened), OrganizationfldName,
Order BY PerMonth desc[/code]
Go to Top of Page

urmas80
Starting Member

20 Posts

Posted - 2013-02-22 : 06:26:14
Thanks! so simple...
Go to Top of Page
   

- Advertisement -