Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2014

    Unanswered: db2 query -- A substitute function for Group By?

    I'm struggling to word this so if it doesn't make sense, I apologize in advance.

    I have a query like this...

    SELECT DISTINCT carton number, location, sum(something) AS eggCount, bad eggs
    GROUP BY carton number, location, bad eggs

    This works, but there's duplicate carton numbers with and without bad eggs.

    I'd like there to pull just carton numbers and a logic that says one or the other, Yes:bad eggs or just a null value.

    In reality, I'm substituting bad eggs for a code called "RE." I don't want a "AA" or "AB" which can show up in place of RE, so Count() doesn't work.

    Is there a way to do this?

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    Sum(CASE WHEN 'RE' = doohickey THEN 1 END) AS BadEggs
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jan 2014
    That works. Thanks Pat Phelan!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts