Solved

count > 1 query

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

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.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

816 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

12 Experts available now in Live!

Get 1:1 Help Now