stupid question, but the solution escapes me

  • I am trying to do something simple - but it is not obvious to me on how to do the following:

    I have a table with 3 columns that I need to use to create a report with.

    productid, qtysold, delivdate

    I need to provide a report that looks like this:

    PRODUCTID SOLD SHIPPED all on one line

    select PRODUCTID, SUM(qtysold) as SHIPPED

    from custitem

    where delivdate is not NULLand PRODUCTID like '17%'

    GROUP BY PRODUCTID

    ORDER BY PRODUCTID

    select PRODUCTID, SUM(qtysold) AS SOLD

    from custitem

    where PRODUCTID like '17%'

    GROUP BY PRODUCTID

    ORDER BY PRODUCTID

    The above 2 queries:

    result 1 = PRODUCTID SHIPPED = 22 products shipped

    result 2 = PRODUCTID SOLD = 1032 products sold

    I have tried several different functions to try to combine these into one line

    PRODUCTID SOLD SHIPPED

    I am sure this is something simple but it escapes me!!!

    HELP

  • Maybe this is simple enough

    select

    PRODUCTID, SUM(qtysold) AS SOLD

    ,

    sum (case when delivdate is NULL then 0 else qtysold end ) as SHIPPED

    from

    custitem

    where

    PRODUCTID like '17%'

    GROUP

    BY PRODUCTID

    ORDER

    BY PRODUCTID

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data and code to get the best help

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Who am I ? Sometimes this is me but most of the time this is me

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

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