Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

count > 1 query

Posted on 2013-11-18
3
Medium Priority
?
192 Views
Last Modified: 2013-11-18
I have the following table design

PlayerID
activitydate

Trying to get a list of playerids that have multiple entries for a specific activitydate

assuming following data

1001  12/01/2012
1002  12/07/2012
1002  07/23/2010
1003  12/01/2012
1001  11//23/2012
1004  03/12/2007
1001  12/01/2012
1002   07/23/2012
1003   12/01/2012

If I am looking for a list of playerid's that occur multiple times for 12/01/2012

I would want the query to return

1001 and 1003

Not sure how to write query
0
Comment
Question by:johnnyg123
3 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 39656868
Give this a whirl..
SELECT playerid
FROM yourtable
WHERE the_date = '2012-12-01'
GROUP BY playerid
HAVING COUNT(playerid) > 1
ORDER BY playerid

Open in new window

btw I have an article out there on SQL Server GROUP BY Solutions, and point #3 deals with HAVING.
0
 
LVL 32

Expert Comment

by:awking00
ID: 39656886
select playerid, count(*) from yourtable
where activitydate = '2012-12-01'
group by playerid
having count(*) > 1
order by playerid;
0
 

Author Closing Comment

by:johnnyg123
ID: 39656934
Perfect!   Thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
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.
Viewers will learn how the fundamental information of how to create a table.

773 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