Displaying Reports by Productname and Region

  • Hi all, Please see example for more details

    I got 3 different tables and my query is

    Select Productaname, Sum(sales), Region from t1 inner join t2 inner join 3

    group by productname, region

    I'm getting results

    Country1

    Sales

    Pdname

    x 10

    y 10

    But i want to display results like below and i want only top 3 records by sales..

    Country1 Country2 Country3

    Sales Sales Sales

    Pdname

    x 10 20 30

    y 10 20 30

    z 10 20 30

    I hope this helps ..thanks

  • Take a look at the pivot command and see if that helps.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Thanks for your reply

    Well, I have used matrix to display results..but i can't get desired result..thanks

  • If you have the country in the results you are looking at, then you drop the country into the columns section of the matrix.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Thank you 4r reply..I got the answer now..I have did same thing before but i have used top in my query..

    the reason for using top query is i want to display top 4 sales amount by prodcutname,country..If i use top in my query it will only giving top 4 out of all countries names..But i want sales top 4 for each country thanks..Please find attached image for more details..thanks

  • nandu.chowdary412 (3/10/2014)


    Thank you 4r reply..I got the answer now..I have did same thing before but i have used top in my query..

    the reason for using top query is i want to display top 4 sales amount by prodcutname,country..If i use top in my query it will only giving top 4 out of all countries names..But i want sales top 4 for each country thanks..Please find attached image for more details..thanks

    Images of data are pretty unfriendly. If you want some coded help, please see the first link in my signature line below under "Helpful Links" for how to post data for your question.

    --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 6 posts - 1 through 5 (of 5 total)

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