Total Sales

  • Hi guys,

    Can someone help please??

    I have two tables (a) Store containing name of store/city, date & sales (b) region & name of store

    My goal is to pull a total sales from region. However, I can only seem to pull the separate cities.

    Can someone have a look at my T-SQL and advise how I should amend this?

    Thanks,

    L

    •select geog.store_name,geog.region_name, sum(sales)

    •AS Total_sales

    •from store_info inner join geog

    •On geog.store_name = store_info.store_name

    •Where geog.region_name = 'west'

    •group by store_info.store_name, geog.store_name,geog.region_name

    •Order by sum(sales) desc

  • Please read this article on how to post query,

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Is this what you need?

    select geog.region_name, sum(sales) AS Total_sales

    from store_info inner join geog

    On geog.store_name = store_info.store_name

    Where geog.region_name = 'west'

    group by geog.region_name

    Order by sum(sales) desc

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

  • Hi Nabha,

    Thanks for the reply. Yes, your amendment is what I was looking for, it was obvious to me once I looked at your code.

    I'll read up on the link you provided.

    Thanks again.

    L

  • Nabha (12/14/2009)


    Please read this article on how to post query,

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Is this what you need?

    select geog.region_name, sum(sales) AS Total_sales

    from store_info inner join geog

    On geog.store_name = store_info.store_name

    Where geog.region_name = 'west'

    group by geog.region_name

    Order by sum(sales) desc

    Nice.

    --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)

  • Thanks Jeff 🙂

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

Viewing 5 posts - 1 through 4 (of 4 total)

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