How to show total sales?

  • Hi Friends,

    My Table struct

    create table cust

    (

    cust_id int ,

    city varchar(20),

    pincode int,

    sales int,

    latitude float,

    longitude float

    )

    insert into cust values(

    '104'

    ,'chennai',

    '600028',

    '50','

    13.0206','

    80.2417')

    values(

    '101'

    ,'chennai',

    '600004',

    '50','

    13.064','

    80.7417')

    values(

    '102'

    ,'chennai',

    '600004',

    '150','

    13.064','

    80.7417')

    values(

    '103'

    ,'chennai',

    '600004',

    '250','

    13.064','

    80.7417')

    expecting o/p:

    cust sales

    101 50

    102 150

    103 250

    TOTAL 450

    for pincode=600004

    like i wanna display each pincodes how to make a code?

  • like i wanna display each pincodes how to make a code?

    what do mean why above statement ?

  • probably you are looking for something like this

    select pincode,sales,SUM(sales) from #cust

    group by pincode,sales with rollup

  • select 'Total '+convert(varchar(10),pincode) as [Total],sum(sales) [Sales]

    from cust

    --where pincode = 600004

    group by convert(varchar(10),pincode)

    Rgds

    Igor Micev,
    My blog: www.igormicev.com

  • Hi ,

    i m doing web application on google maps depends lat,long ll show marker on map

    create table location

    (

    id int identity,

    city varchar(20),

    lattitude float,

    lontitude float

    descn

    )

    insert into locations values('chennai','13.062','80.641','Welcome to chennai')

    so when i run my application its default show marker on chennai when i press the marker its open info window with "Welcome to chennai".

    now my requirement is

    each state i wanna show area wise (pincodes wise)marker in that description display the details of customer wise sales and total)

    so how to make code ?

  • twin.devil (3/10/2014)


    like i wanna display each pincodes how to make a code?

    what do mean why above statement ?

    Maybe this:

    select pincode,SUM(sales) from cust

    group by pincode

    Igor Micev,
    My blog: www.igormicev.com

  • If you need both subtotals and total see GROUP BY ROLLUP

    http://technet.microsoft.com/ru-ru/library/ms177673.aspx

Viewing 7 posts - 1 through 6 (of 6 total)

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