Solved

How can I write a query to return a count for each day ongoing with date columns vertical?

Posted on 2016-08-01
3
41 Views
Last Modified: 2016-08-02
Hello, I'm trying to write a query that will return the number of tickets each person works, each day. I'd like to have the names going down the left side, and each day's date going across the top, with the count for each person below the date. I'd like for it to run across like this for 1 rolling year, if possible. It should look like below (sample data is below this example):
         8/1/2016     8/2/2016    etc....
Bob        3                    1          etc...
Sally       2                    1          etc...
John       1                    2          etc...

Each number is a count of records closed that day by the user, a sample of the data would look like this

ID UserName DateTicketClosed
1    Bob              8/1/2016
2    Bob              8/1/2016
3    Bob              8/1/2016
4    Bob              8/2/2016
5     Sally            8/1/2016
6     Sally            8/1/2016
7     Sally            8/2/2016
8     John            8/1/2016
9     John            8/2/2016
10   John            8/2/2016

Could someone assist?
0
Comment
Question by:earwig75
3 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 500 total points
ID: 41737801
SQL as a database language standard doesn't have such feature, as its goal is to retrieve data organized by rows. So any resulting record is on a row, and columns are used for attributes (also called fields or even columns).

However, you can reach this by using some tools like Oracle Reports, which is more related on how to present this information to user.

Hope it helps. Regards.
0
 
LVL 40

Expert Comment

by:Sharath
ID: 41738153
Can be done. Let me know if you are still looking for a sql query.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41738824
"PIVOT"
is the T-SQL feature provided for this type of output

or: use of case expressions, aggregate functions and a group by
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now