SQL Server Aggregate Query

SM 21 Reputation points
2020-08-21T14:12:02.877+00:00

I need to write a query that returns the ID of the items counted to find duplicates.

I have a Transaction table with Procedures and need to find accounts where COUNT(Procedure)>1 GROUP BY Account. That part I can do. I don't know how to return the primary key IDs of the records used in the COUNT.

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,589 questions
0 comments No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. tibor_karaszi@hotmail.com 4,306 Reputation points
    2020-08-21T16:02:23.79+00:00

    So you want to refer to detailed rows, lost by the aggregation? Than you can't use just one query. You can for instance join your GROUP BY query to another query that get the detailed data. No need to store the intermediate stuff in a temp table, you can use derived table or CTE. Without DDL and an executable example, it is about as far as we can go.

    0 comments No comments

  2. EchoLiu-MSFT 14,576 Reputation points
    2020-08-24T09:49:00.597+00:00

    Hi @SM ,
    I am very happy that your problem has been solved.
    If you have any question, please feel free to let me know.

    Best Regards
    Echo

    0 comments No comments