Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Summing oddly organized numbers sequence 1

Status
Not open for further replies.

mptwoadmin

Programmer
May 15, 2006
46
0
0
US
Hi could I get a hand on how I would sum the following number sequence. The datetimes can change as well as the values. Im trying to get a handle on just summing these values. I have a starting value of 78913 and an ending value of 3212.

Datetime Value
3/22/12 15:40 78913
3/22/12 15:42 78913
3/22/12 15:44 78913
3/22/12 15:46 0
3/22/12 15:47 0
3/22/12 15:49 0
3/22/12 15:51 0
3/22/12 15:53 0
3/22/12 15:55 0
3/22/12 15:57 0
3/22/12 15:59 0
3/22/12 16:01 0
3/22/12 16:02 0
3/22/12 16:04 0
3/22/12 16:06 0
3/22/12 16:08 0
3/22/12 16:10 0
3/22/12 16:12 0
3/22/12 16:14 0
3/22/12 16:16 0
3/22/12 16:17 0
3/22/12 16:19 0
3/22/12 16:21 0
3/22/12 16:23 133
3/22/12 16:25 520
3/22/12 16:27 915
3/22/12 16:29 1304
3/22/12 16:31 1659
3/22/12 16:32 2048
3/22/12 16:34 2438
3/22/12 16:36 2823
3/22/12 16:38 3212



 
Based on your sample data, what is your expected result?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Sorry I needed to edit my data i posted.

I have a starting value of 78000 and an ending value of 3212.


Datetime Value
3/22/12 15:40 78000
3/22/12 15:42 78100
3/22/12 15:44 78913
3/22/12 15:46 0
3/22/12 15:47 0
3/22/12 15:49 0
3/22/12 15:51 0
3/22/12 15:53 0
3/22/12 15:55 0
3/22/12 15:57 0
3/22/12 15:59 0
3/22/12 16:01 0
3/22/12 16:02 0
3/22/12 16:04 0
3/22/12 16:06 0
3/22/12 16:08 0
3/22/12 16:10 0
3/22/12 16:12 0
3/22/12 16:14 0
3/22/12 16:16 0
3/22/12 16:17 0
3/22/12 16:19 0
3/22/12 16:21 0
3/22/12 16:23 133
3/22/12 16:25 520
3/22/12 16:27 915
3/22/12 16:29 1304
3/22/12 16:31 1659
3/22/12 16:32 2048
3/22/12 16:34 2438
3/22/12 16:36 2823
3/22/12 16:38 3212
 
My expected results should be 3992 from this grouping of data.
 
I *love* guessing games!
Is it a statistical function?
Oh wait, maybe an interval function...Fibonacci? Am I getting close?

soi là, soi carré
 
<<Hi could I get a hand on how I would sum the following number sequence.>>

Simple:

SELECT SUM(Value) FROM WhateverTable

<<The datetimes can change as well as the values.>>
How is that relevant?

<<I have a starting value of 78913 and an ending value of 3212.>>
How is that relevant?

<<My expected results should be 3992 from this grouping of data.>>
Using what logic or formulas?


 
im sorry, I summed incorrectly the other day.
3/22/12 15:40 78000
3/22/12 15:42 78100
3/22/12 15:44 78913
= 78000 - 78913 = "913"

3/22/12 16:38 3212
= 913 + 3212 = 4125 - expected results

i am trying to sum values prior to "3/22/12 15:45" then the values after "3/22/12 15:45".
 
It's not really just a sum if you're taking the difference between 78913 and 78000.

On the information in your last post, here's some code that gives you 78913-78000+3212 = 4125:
Code:
SELECT 
(SELECT valuefield FROM mytable WHERE datefield = (SELECT max(datefield) FROM mytable WHERE datefield < '2012-03-22 15:45:00.000'))
- 
(SELECT valuefield FROM mytable WHERE datefield = (SELECT min(datefield) FROM mytable WHERE datefield < '2012-03-22 15:45:00.000'))
+
(SELECT valuefield FROM mytable WHERE datefield = (SELECT  max(datefield) FROM mytable WHERE datefield > '2012-03-22 15:45:00.000'))

soi là, soi carré
 
Thanks I guess I was thinking too much into it; rather than a simple explaination.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top