Return Records with Count > 2

  • This is probably an easy and obvious problem, but I can't get the right syntax.

    Select a.Company, a.Contact, a.CustomerNumber, a.State, a.City From Table a

    I only want to return records where a count(*) of CustomerNumber and State are more than 1.  I cannot use the Group function since the City would be different.

     

    Thanks!

     

     

  • I have no idea of what is unique on your data but this is a start

    Select a.Company, a.Contact, a.CustomerNumber, a.State, a.City From

        Table a

    join

        (

         select CustomerNumber, State 

         from TableA

         group by CustomerNumber, State

         having Count(*) >2 ) SubQ

         on SubQ.CustomerNumber = a.CustomerNumber and  SubQ.state = a.state

     

    hth


    * Noel

  • Thanks Noel.  That makes perfect sense and should work.  I appreciate the help!

  • Cheers!


    * Noel

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

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