Solved

count > 1 query

Posted on 2013-11-18
3
172 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 65

Accepted Solution

by:
Jim Horn earned 500 total points
Comment Utility
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 31

Expert Comment

by:awking00
Comment Utility
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
Comment Utility
Perfect!   Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ms sql stored procedure 22 75
Help with SQL Query 23 39
How many Lat/Long for a single UK Postcode 5 10
BULK INSERT most recent CSV 19 17
Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

772 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

14 Experts available now in Live!

Get 1:1 Help Now