Unix Technical Forum

Sum Accumulating Data

This is a discussion on Sum Accumulating Data within the SQL Server forums, part of the Microsoft SQL Server category; --> So, does my code meet the requirement? -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA SQL Server ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

 

LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 02-29-2008, 08:10 PM
Tom Moreau
 
Posts: n/a
Default Re: Sum Accumulating Data

So, does my code meet the requirement?

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
..
<sucaba.r@gmail.com> wrote in message
news:1145448102.311646.16480@g10g2000cwb.googlegro ups.com...
Hi Tom,

>From looking at the table, the system ran for three days before it was

reset (rows 1-3). It then ran for 4 days (rows 4-7) for a total of 7
(not 5 as I indicated above). So I'd need to capture 7 as the total.

Thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 02-29-2008, 08:10 PM
sucaba.r@gmail.com
 
Posts: n/a
Default Re: Sum Accumulating Data

Thanks for the help (and lecture). Tom, forgive my ignorance, but your
code is producing 9 instead of 7.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 02-29-2008, 08:10 PM
Alexander Kuznetsov
 
Posts: n/a
Default Re: Sum Accumulating Data

> Here is a query based on Tom's table, but it returns 6 and not 7, because the first row is not counted

If there are gaps in PK, it gets slightly more exciting:

select count(*) from #t t1 join #t t2
on t1.PK < t2.PK
and t1. Amount < t2.amount
where not exists(
select 1 from #t t3
where (t1.PK < t3.PK) and (t3.PK < t2.PK)
)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 02-29-2008, 08:10 PM
Tom Moreau
 
Posts: n/a
Default Re: Sum Accumulating Data

Now, I am even more confused. What's wrong with entry #8? What
disqualifies it? You say that it ran from 4 - 7, though 8 is also part of
the same progression.

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
..
<sucaba.r@gmail.com> wrote in message
news:1145541923.733297.75130@t31g2000cwb.googlegro ups.com...
Thanks for the help (and lecture). Tom, forgive my ignorance, but your
code is producing 9 instead of 7.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 02-29-2008, 08:11 PM
sucaba.r@gmail.com
 
Posts: n/a
Default Re: Sum Accumulating Data

I too am confused. :-) I'll try and explain what I mean. Here's the
table data again, notated on the right with asterisks that count as
legitimate data points:

1 - 239.21 *
2 - 239.55 *
3 - 240.30 *
4 - 0.35
5 - 0.44 *
6 - 0.53 *
7 - 1.20 *
8 - 2.40 *
9 - 0.25

So the uptime query should return 7, as the machine was reset at
location 4 and 9.

Sorry for the confusion.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 02-29-2008, 08:11 PM
Hugo Kornelis
 
Posts: n/a
Default Re: Sum Accumulating Data

On 21 Apr 2006 06:12:15 -0700, sucaba.r@gmail.com wrote:

>I too am confused. :-) I'll try and explain what I mean. Here's the
>table data again, notated on the right with asterisks that count as
>legitimate data points:
>
>1 - 239.21 *
>2 - 239.55 *
>3 - 240.30 *
>4 - 0.35
>5 - 0.44 *
>6 - 0.53 *
>7 - 1.20 *
>8 - 2.40 *
>9 - 0.25
>
>So the uptime query should return 7, as the machine was reset at
>location 4 and 9.
>
>Sorry for the confusion.


Hi sucaba,

Slight modification of Erland's suggestion (it was thus far unclear if
the "first" data point had to be included, since there's no "previous"
value to compare to - Erland apparently chose to exclude it):

SELECT COUNT(*)
FROM @t AS a
LEFT OUTER JOIN @t AS b
ON a.PK = b.PK + 1
WHERE a.Amount > b.Amount
OR b.Amount IS NULL


--
Hugo Kornelis, SQL Server MVP
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 02-29-2008, 08:11 PM
Tom Moreau
 
Posts: n/a
Default Re: Sum Accumulating Data

And what is wrong with entry 9?

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
..
<sucaba.r@gmail.com> wrote in message
news:1145625135.604955.307690@i40g2000cwc.googlegr oups.com...
I too am confused. :-) I'll try and explain what I mean. Here's the
table data again, notated on the right with asterisks that count as
legitimate data points:

1 - 239.21 *
2 - 239.55 *
3 - 240.30 *
4 - 0.35
5 - 0.44 *
6 - 0.53 *
7 - 1.20 *
8 - 2.40 *
9 - 0.25

So the uptime query should return 7, as the machine was reset at
location 4 and 9.

Sorry for the confusion.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 02-29-2008, 08:11 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Sum Accumulating Data

Tom Moreau (tom@dont.spam.me.cips.ca) writes:
> And what is wrong with entry 9?


0.25 < 2.40

or so I guess.

But it's difficult when sucaba.r does not really seem to have a grip
on it him/herself.

Maybe because it's some class assignment, and not a real-world case, who
knows.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 02-29-2008, 08:11 PM
Tom Moreau
 
Posts: n/a
Default Re: Sum Accumulating Data

The specs are confusing - and fluid. My guess is if he wants 7 so bad, then
this is the solution:

SELECT 7

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
..
"Erland Sommarskog" <esquel@sommarskog.se> wrote in message
news:Xns97AD85A38BDF9Yazorman@127.0.0.1...
Tom Moreau (tom@dont.spam.me.cips.ca) writes:
> And what is wrong with entry 9?


0.25 < 2.40

or so I guess.

But it's difficult when sucaba.r does not really seem to have a grip
on it him/herself.

Maybe because it's some class assignment, and not a real-world case, who
knows.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 02-29-2008, 08:12 PM
sucaba.r@gmail.com
 
Posts: n/a
Default Re: Sum Accumulating Data

My apology for not making myself clear enough, and yes it's real-world.
Thanks again for all the help guys.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:53 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com