Counting separate PO numbers for a part

For the PO table layout below:

PoNum    Part
53831    M1    
53831    M1
53832    M1
53833    M2
53831    M2

I need to return that M1 is on two seperate PoNums and M2 is on two PoNums. Any help is greatly appreciated.

    Requires Free Membership to View

    By submitting your registration information to SearchOracle.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchOracle.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

"Separate" PoNums can be counted using the DISTINCT keyword in the COUNT function:

select Part
     , count(distinct PoNum) as PoNums
  from PO
group
    by Part

Easy when you see it, eh?

This was first published in May 2006

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.