Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2008
    Posts
    2

    Unanswered: Analytical functions

    Hi All,

    i have a table like this:

    day_hour_of_call cost_of_call

    2008-01-01 20:34:06 10
    2008-01-01 16:54:01 20
    2008-01-02 19:44:04 5
    2008-01-03 22:14:01 5
    ............... ............
    2008-02-01 19:11:05 5
    2008-02-02 02:32:01 12


    I would like to have:
    referral_day sum_of_cost_from_beginning_to_referral_day
    2008-01-01 10+20
    2008-01-02 5+20+10
    2008-01-03 5+5+20+10
    ............... ............
    2008-02-01
    2008-02-02



    Is it possible ?

    Thanks,
    Marco

  2. #2
    Join Date
    Dec 2007
    Location
    Chennai,India
    Posts
    12
    select day,sum(cost)
    from table
    group by day

  3. #3
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    take a look at the COMPUTE clause of the SELECT statement

  4. #4
    Join Date
    Oct 2008
    Posts
    2
    Hi ! I'm using Sybase IQ 12.7.

    select day,sum(cost) from table group by day doesn't works because I need the sum of cost from beginning (1900-01-01) to referral day.

  5. #5
    Join Date
    Dec 2007
    Location
    Chennai,India
    Posts
    12
    derive a table,say #tmp1,from your table having one row for each unique date ,like

    rday(datetime) cost(int)
    2008-01-01 00:00:00.000 30
    2008-01-02 00:00:00.000 5
    2008-01-03 00:00:00.000 5
    select a.rday,sum(b.cost) cost
    from #tmp1 a,#tmp1 b
    where b.rday <= a.rday
    group by a.rday

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •