Using group by with multiple fields

  • Hello,

    Could someone please tell if there was a way to use group by with one field when there are multiple fields in the select statement and at the same time also sum one of the fields(not rhe group by one) ?

    foe e.g. i need to achieve this:

    -----------------------------------

    Select BL_ID,

    sum(D.FRT_USD) as FRT_USD,

    TEU,

    SAISAN_MONTH

    from tablename

    group by BL_ID

    -----------------------------------

    Thanks,

    Paul

  • Depending on your required output

    Select BL_ID,

    sum(D.FRT_USD) as FRT_USD,

    TEU,

    SAISAN_MONTH

    from tablename

    group by BL_ID,TEU,SAISAN_MONTH

    Or

    Select BL_ID,

    sum(D.FRT_USD) as FRT_USD,

    MIN(TEU) as Min_TEU,

    MIN(SAISAN_MONTH) AS Min_SAISAN_MONTH

    from tablename

    group by BL_ID

    Or there might be the need of a subquery. It depends.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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