Question about grouping and adding

  • I have the following query:

    SELECT DISTINCT Case_Code, (glued + plant) as Glued, flat

    FROM Carton_Inventory.dbo.vwscheduledcasesavailable3

    WHERE [date]>='9/11/2009'

    The following data is returned:

    CASECODE Glued flat

    00365 30

    00365 23.50

    01302 90

    01302 435

    02725 200

    05789 41.850

    07504 13.262

    07922 8.20

    17648 114101

    31828 31.617

    31833 965

    31833 330

    31843 32.50

    31845 76

    31920 1690

    37993 1627

    47543 7.40

    If I select * from the query, I get the following (this is sample data based on 00365):

    DATE CASE CODE CARTON SAP LINE GLUED flat plant hold

    2009-09-19 00:00:00.00000365 8701KK117456077101-0002 23.5000

    2009-09-20 00:00:00.00000365 8701KK117456077101-0002 23.5000

    2009-09-18 00:00:00.00000365 8701KK117456077101-0002 23.5000

    2009-09-18 00:00:00.00000365 8701BK117456079101-0002 3000

    2009-09-19 00:00:00.00000365 8701BK117456079101-0002 3000

    2009-09-20 00:00:00.00000365 8701BK117456079101-0002 3000

    Ultimately what I want returned is this grouped so it would return:

    Case Code TotalGlued

    00365 26.5

    Other columns do not really pertain to what I need returned. Of course when I group a sum on glued I get 79.5, which is what I do not want.

    Thanks for any information.

  • Brad Allison (9/11/2009)


    I have the following query:

    SELECT DISTINCT Case_Code, (glued + plant) as Glued, flat

    FROM Carton_Inventory.dbo.vwscheduledcasesavailable3

    WHERE [date]>='9/11/2009'

    The following data is returned:

    CASECODE Glued flat

    00365 30

    00365 23.50

    01302 90

    01302 435

    02725 200

    05789 41.850

    07504 13.262

    07922 8.20

    17648 114101

    31828 31.617

    31833 965

    31833 330

    31843 32.50

    31845 76

    31920 1690

    37993 1627

    47543 7.40

    If I select * from the query, I get the following (this is sample data based on 00365):

    DATE CASE CODE CARTON SAP LINE GLUED flat plant hold

    2009-09-19 00:00:00.00000365 8701KK117456077101-0002 23.5000

    2009-09-20 00:00:00.00000365 8701KK117456077101-0002 23.5000

    2009-09-18 00:00:00.00000365 8701KK117456077101-0002 23.5000

    2009-09-18 00:00:00.00000365 8701BK117456079101-0002 3000

    2009-09-19 00:00:00.00000365 8701BK117456079101-0002 3000

    2009-09-20 00:00:00.00000365 8701BK117456079101-0002 3000

    Ultimately what I want returned is this grouped so it would return:

    Case Code TotalGlued

    00365 26.5

    Other columns do not really pertain to what I need returned. Of course when I group a sum on glued I get 79.5, which is what I do not want.

    Thanks for any information.

    Could you do something like this?

    select case_code, sum(glued) from

    (

    select distinct case_code, glued from

    Carton_Inventory.dbo.vwscheduledcasesavailable3

    WHERE [date]>='9/11/2009'

    ) test

    group by case_code

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

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