Daily sum aggregation

  • I have a problem that requires me to write Daily sum aggregation script, I wrote the script; But what I'm not sure of is the "Daily" part, my script will give me only give me results when I execute it.

    Can you help me on how to make this code daily?

    SELECT

    Receipt

    ,"Date"

    ,Item

    ,Reason

    ,Division

    ,SUM(Cost) AS Cost

    FROM Cost

    WHERE Item IN ('Z001', 'Z002')

    GROUP BY

    Receipt

    ,Date

    ,Item

    ,Reason

    ,Division

  • hoseam (7/14/2015)


    I have a problem that requires me to write Daily sum aggregation script, I wrote the script; But what I'm not sure of is the "Daily" part, my script will give me only give me results when I execute it.

    Can you help me on how to make this code daily?

    SELECT

    Receipt

    ,"Date"

    ,Item

    ,Reason

    ,Division

    ,SUM(Cost) AS Cost

    FROM Cost

    WHERE Item IN ('Z001', 'Z002')

    GROUP BY

    Receipt

    ,Date

    ,Item

    ,Reason

    ,Division

    Unless the Receipt, Reason, and Division fields are unique to the Item, you're going to have trouble due to how this is grouped. I can see item being unique within a Division, but I wouldn't necessarily count on it. What, exactly, does the Reason field bring into the result? Is that a return reason, a sales reason, or some other reason? I'm asking because you're grouping on it, and that might not be something unique to a given item. If you're looking for a SUM aggregate for a given item by day, then you need to only group by those fields. Once you determine where you have uniqueness, you can group by only those fields and get a good result. If you could post some CREATE TABLE statements and some INSERT statements with sample data and expected results, we can help much further.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

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

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