SQL query which returns a single aggregate metric indicating how well actuals met forecast for a given week

  • Table: UnitsSold
    Columns:
    •    ProductID
    •    Quantity
    •    Date
    •    ForecastOrActual – can be “A” for actual and “F” for forecast.

    Sample Data would look like this:
    UnitsSold
    ProductID        Quantity    Date    ForecastOrActual
    Widget    100    1-June-2015    F
    Widget    120    1-June-2015    A
    Gizmo    90    1-June-2015    F
    Gizmo    80    1-June-2015    A
    Doohickey    200    1-June-2015    A

    Write an SQL query which returns a single aggregate metric indicating how well actuals met forecast for a given week. What assumptions did you make?

  • jeswar - Saturday, March 4, 2017 12:18 AM

    Table: UnitsSold
    Columns:
    •    ProductID
    •    Quantity
    •    Date
    •    ForecastOrActual – can be “A†for actual and “F†for forecast.

    Sample Data would look like this:
    UnitsSold
    ProductID        Quantity    Date    ForecastOrActual
    Widget    100    1-June-2015    F
    Widget    120    1-June-2015    A
    Gizmo    90    1-June-2015    F
    Gizmo    80    1-June-2015    A
    Doohickey    200    1-June-2015    A

    Write an SQL query which returns a single aggregate metric indicating how well actuals met forecast for a given week. What assumptions did you make?

    looks very much like a homework question to me......what have you tried so far and what are the results you expect to return?

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • jeswar - Saturday, March 4, 2017 12:18 AM

    Table: UnitsSold
    Columns:
    •    ProductID
    •    Quantity
    •    Date
    •    ForecastOrActual – can be “A†for actual and “F†for forecast.

    Sample Data would look like this:
    UnitsSold
    ProductID        Quantity    Date    ForecastOrActual
    Widget    100    1-June-2015    F
    Widget    120    1-June-2015    A
    Gizmo    90    1-June-2015    F
    Gizmo    80    1-June-2015    A
    Doohickey    200    1-June-2015    A

    Write an SQL query which returns a single aggregate metric indicating how well actuals met forecast for a given week. What assumptions did you make?

    Agreed.  Looks like homework or a test.

    Either your instructor just got done teaching about self-joins or just got done teaching about Lead/Lag.  Review what your instructor taught and give it a shot.  For goodness sake, do it on your own so that you actually know something about T-SQL if you happen to pass the course.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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