Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Confused about count function Expand / Collapse
Author
Message
Posted Tuesday, December 04, 2012 10:02 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, June 13, 2013 1:20 PM
Points: 143, Visits: 489
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
Post #1392597
Posted Tuesday, December 04, 2012 10:18 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: 2 days ago @ 4:48 PM
Points: 834, Visits: 5,836
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
Post #1392605
Posted Tuesday, December 04, 2012 10:28 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, June 13, 2013 1:20 PM
Points: 143, Visits: 489
Thank you David!
Post #1392615
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse