How to calculate sum value in these table

  • create table cust_details

    (

    id int ,

    city varchar(20),

    cust_name varchar(20),

    sales int

    )

    insert into cust_details

    values('1','Tamilnadu','101','500'),

    values('2','Tamilnadu','102','300'),

    values('3','Pondi','103','200'),

    values('4','Pondi','104','100')

    my expecting o/p:

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

    city customer sales

    tamilnadu 101 500

    102 300

    ------

    total 800

    -------

    or

    customer sales

    101 500

    102 300

    total 800

    like i wanna display separate loction?

  • How about SSRS?

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • Give this a try:SELECT City, cust_name [Customer], SUM(sales) [Sales] FROM cust_details

    WHERE city = 'Tamilnadu'

    GROUP BY GROUPING SETS ((city, cust_name), ())

    SELECT cust_name [Customer], SUM(sales) [Sales] FROM cust_details

    WHERE city = 'Tamilnadu'

    GROUP BY GROUPING SETS ((cust_name), ())

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

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

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