Group By

  • Hi Guys

    Can You guys help me to understand Group By Query By Using The function. I am unable to understand that how it works. I practicing on Adventure works2008 and unable to understand the the funds they are using group By query and how we have to combine it with the function like count, sum etc.............

    Please help me to understand this concept

    Thanks in Advance for your help

    Regard Rishi

  • Hi

    Well, GROUP BY means to group several rows by specified columns... It aggregates rows so that there are no more duplicate rows for the specified columns.

    DECLARE @orders TABLE (Amount DECIMAL(15,2), Customer INT);

    INSERT INTO @orders

    SELECT 10.00, 1

    UNION ALL SELECT 20.00, 2

    UNION ALL SELECT 30.00, 1;

    SELECT

    Customer

    ,SUM(Amount)

    ,COUNT(*)

    FROM @orders

    GROUP BY Customer;

    Two rows for customer 1 are aggregated to one row and SUM/COUNT are used to return aggregated values.

    For further information, please hit BOL.

    Greets

    Flo

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

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