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
 Outputing Data In a Specific Layout - Need Help

Author  Topic 

Jonathan0624
Starting Member

2 Posts

Posted - 2011-01-12 : 12:34:13
Hello Everyone. I've been wrestling with my head in order to try to get some data outputed the way I need it, but I just can't get it right. I'm not a database guru, so please forgive me if I use the wrong terminology.

I have two tables; USERS and ISSUES, and I am trying to output the total number of issues entered by 5 specific users in this format:

Users TotalIssues
------------------
BSmith 30
JDoe 45
KGarnet 22
MJordan 23
JStarks 3

The users table contains more than 1,000 users, and the issues table contains more that 40,000 entries.

Here is some info on the two tables:

The users table contains the following columns (i've also put in some sample data):

USERNUMBER, USERID
------------------
1 MJordan
2 KGarnett
3 JStarks

The Issues Table contains the following columns (i've also put in some sample data):

IssueNumber, EnteredBy
----------------------
234 MJordan
776 JStark
7763 JonJon


Both UserID.Users and ISSUES.EnteredBy are identical.

How would I go about getting the total number of issues entered by 5 specific people in this format:

Users TotalIssues
------------------
BSmith 30
JDoe 45
KGarnet 22
MJordan 23
JStarks 3


Thanks for your help!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-12 : 12:38:48
[code]
SELECT u.Userid, COUNT(IssueNumber) AS TotalIssues
FROM Users u
INNER JOIN Issues i
ON i.EnteredBy = u.UserID
WHERE u.UserID IN ('BSmith','JDoe','KGarnet','MJordan','JStarks')
GROUP BY u.Userid
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Jonathan0624
Starting Member

2 Posts

Posted - 2011-01-12 : 12:53:53
Thank you so much. That produced the exact results that I was seeking.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-12 : 12:55:28
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -