COUNT Question

  • I have looked through old threads, and could not find this addressed. Basically I have a query that identifies various transactions. Each transaction has a corresponding employee ID attached. Is there a way to pull up these transactions, and display how many times each ID appears in the results? So ultimately, I can say employee 'X' has 32 transactions and employee 'Y' has 15.

  • Look up Count in Books Online, and Group By.

    Basically, it's going to look like:

    select EmployeeID, count(*)

    from dbo.MyTable

    group by EmployeeID;

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thanks! Worked like a charm.

  • I'd recommend learning some of the basics...

    http://sqlcourse.com/

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • *Bookmarked* Thanks.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply