Solved

How to group by date?

Posted on 2011-09-21
6
163 Views
Last Modified: 2012-06-27
In the following, how do I get a count for each unique day entry on a ticketid for an employee?

In the example below, empid=1 and ticketid=7 would have a count of 3, since it was worked on three different days.  However, empid=1 and ticketid=9 is just one day, since both entries were on 9/17. empid=3 and ticketid=9 is also one day since both entries were on 9/17 as well.
Id   empid   ticketid   datecomplete              ticketsession
4      1         9      2011-09-17 9:12:24.000        3
4      1         9      2011-09-17 9:12:24.000        3
10     1         7      2011-09-15 9:12:24.000        7
19     1         7      2011-09-16 9:12:24.000        7
20     1         7      2011-09-17 11:17:24.000        7
21     3         9      2011-09-17 9:12:24.000        3
21     3         9      2011-09-17 10:12:24.000        3

Open in new window

0
Comment
Question by:brettr
  • 3
  • 3
6 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 36576102
try
select empid, CONVERT(varchar(10), datecomplete, 101) datecomplete
from table1
group by empid, CONVERT(varchar(10), datecomplete, 101)

Open in new window

0
 

Author Comment

by:brettr
ID: 36576173
Sorry - accepted too soon.  What I want is the count of 3 for empid=1 and ticketid=7.  The above query keep them on separate rows and doesn't provide a count.
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 36576201
Add the counts to your select query


select empid, count(empid) [Employees], count(tickectid) [tickectid], CONVERT(varchar(10), datecomplete, 101) datecomplete
from table1
group by empid, tickectid, CONVERT(varchar(10), datecomplete, 101)

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:brettr
ID: 36576254
That just counts each single row.  So instead of getting 3 for 9/15, 9/16 and 9/17, which were all on the same ticket, you can 1 for each.
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 36576440
Right, you only need one count but group by the two fields

select empid, count(tickectid) [Tickect Count], CONVERT(varchar(10), datecomplete, 101) datecomplete
from table1
group by empid, tickectid, CONVERT(varchar(10), datecomplete, 101)

Open in new window

0
 

Author Comment

by:brettr
ID: 36576457
ok, thanks.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question