I need the total count of Products but i only have a line qty for each subproduct

  • Paraphrasing my data -----My table only has the qty for each Prod ID. . . but i need the total number of apples .  . .. as in the last column.  I hope that is enough to go on.  Unseen columns have distinct data, so i cant do Distinct.  thanks 

    PROD_ID

    Prod_Desc

    Prod ID Qty

     

    Prod ID Qty

    Granny SmithApple4444
    Granny SmithApple44609
    Granny SmithApple44581
    Granny SmithApple4470
    Granny SmithApple4482
    MacintoshApple60963
    MacintoshApple6091449
    MacintoshApple609
    MacintoshApple609I want the total count of Apples
    MacintoshApple609
    GreenApple581
    GreenApple581
    GreenApple581
    GreenApple581
    GreenApple581
    FujiApple70
    FujiApple70
    FujiApple70
    FujiApple70
    FujiApple70
    GalaApple82
    GalaApple82
    GalaApple82
    GalaApple82
    GalaApple82
    HoneyCrispApple63
    HoneyCrispApple63
    HoneyCrispApple63
    HoneyCrispApple63
    HoneyCrispApple63
  • Please provide sample DDL and INSERTs for your data. I think you may need to expand on the summing logic you require too, as I do not understand it as written.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • It's not quite clear what you are looking for, but I think this is what you want...

    -- You can do distinct, just dont do it against the entire record. Use a subquery to eliminate all the other columns first, then sum that subquery. If you just want a result that shows the total number of apples:
    select
        sum( PROD_ID_QTY ) TOTAL_APPLES
      from ( select distinct PROD_DESC, PROD_ID_QTY from <your table> ) a
     group by
         PROD_DESC

    Otherwise, as Phil said, the question is't quite clear. How you have the sample data layed out is somewhat confusing.

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

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