Home All Groups Group Topic Archive Search About

subquery or cursor needed here?

Author
11 Aug 2006 10:02 PM
Steve Hershoff
Hi everybody,

I have a table with three columns-- empno (int, primary key), transtype
(int) and transdate (datetime).  I'd like a listing of all empnos that have
identical transtype/transdate pairs, along with the count of how many times
such pairings occur.  I'm not so interested in what the pairs' values are,
just that there are duplicates.

So, for example, if empno 33 had these values in the table:

empno        transtype            transdate
33                   88                  2/7/2001
33                   89                  5/13/2001
33                   88                  2/7/2001

....I would want to see this in my result:

empno        cnt
33               2

How can I do this?  Thanks very much.

Author
11 Aug 2006 10:17 PM
Michael Keating
Hi,

A simple agregate function will do the trick, as in;

SELECT     EmpNo, TransType, COUNT(TransType) AS [Count]
FROM         TableName
GROUP BY EmpNo, TransType
HAVING      (COUNT(TransType) > 1)

MFK


Show quote
"Steve Hershoff" <babba***@nowhere.com> wrote in message
news:%23wzUnHZvGHA.560@TK2MSFTNGP05.phx.gbl...
> Hi everybody,
>
> I have a table with three columns-- empno (int, primary key), transtype
> (int) and transdate (datetime).  I'd like a listing of all empnos that
> have identical transtype/transdate pairs, along with the count of how many
> times such pairings occur.  I'm not so interested in what the pairs'
> values are, just that there are duplicates.
>
> So, for example, if empno 33 had these values in the table:
>
> empno        transtype            transdate
> 33                   88                  2/7/2001
> 33                   89                  5/13/2001
> 33                   88                  2/7/2001
>
> ...I would want to see this in my result:
>
> empno        cnt
> 33               2
>
> How can I do this?  Thanks very much.
>
Author
12 Aug 2006 12:05 AM
Steve Hershoff
Thanks Michael!

-Steve

Show quote
"Michael Keating" <michael.keat***@shoooo.dsl.pipex.com> wrote in message
news:ZPidnQ1NgLSYn0DZnZ2dnUVZ8qudnZ2d@pipex.net...
> Hi,
>
> A simple agregate function will do the trick, as in;
>
> SELECT     EmpNo, TransType, COUNT(TransType) AS [Count]
> FROM         TableName
> GROUP BY EmpNo, TransType
> HAVING      (COUNT(TransType) > 1)
>
> MFK
>
>

AddThis Social Bookmark Button