Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

count > 1 query

Posted on 2013-11-18
3
Medium Priority
?
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

722 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