Confused about count function

  • Hello,

    I can't wrap my head around what the below query does when it includes a having count(*) > 1 and used with the group by? Can someone please help me understand this?

    SELECT

    RxNbr,

    RefillNo

    FROM

    dbo.POSRx AS pr

    WHERE

    DateFilledSK >= 20120901

    AND Void = 0

    GROUP BY

    RxNbr,

    RefillNo

    HAVING

    COUNT(*) > 1

    Thanks,

    Sean

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • It's looking for duplicates. It will only show rows where there is more than 1 instance of the combination of columns in the 'group by'.


    And then again, I might be wrong ...
    David Webb

  • Thank you David!

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

Viewing 3 posts - 1 through 2 (of 2 total)

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