473,854 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparing data in two consecutive rows from a single table

I'm trying to come up with an elegant, simple way to compare two
consecutive values from the same table.

For instance:

SELECT TOP 2 datavalues FROM myTable ORDER BY timestamp DESC

That gives me the two latest values. I want to test the rate of
change of these values. If the top row is a 50% increase over the row
below it, I'll execute some special logic.

What are my options? The only ways I can think of doing this are
pretty ugly. Any help is very much appreciated. Thanks!

B.
Jul 20 '05
22 24680
>> So why not? I bet the underlying business problem looks a whole
like
that! <<

Copying a paper form directly into a RDBMS is not a good idea. This
problem sounds like a history; history is a series of durations.
You know, most people who are using databases are trying to solve

real-world problems, not do exercises in relational algebra. <<

That is like saying the people at Enron ignored math because they "are
trying to solve real-world problems, not do exercises in relational
algebra" :)
Jul 20 '05 #11
--CELKO-- wrote:
That is like saying the people at Enron ignored math because they "are
trying to solve real-world problems, not do exercises in relational
algebra" :)


Actually, they were trying to *avoid* real-world problems. ;)

Zach
Jul 20 '05 #12

"--CELKO--" <jc*******@eart hlink.net> wrote in message
news:18******** *************** **@posting.goog le.com...
I have to disagree here Joe. For example, one of our tables
records the time a banner ad is served. There's no "begin and end"
there's an instant. <<

Your banner ads have no duration? Wow! That means that if I want to
run 1000 ads, and a database that records times to 1/1000 of a second,
then I can put 1000 ads in each second :)


Serving them has no duration, no.

And we serve (and record the serving) of over 14 million banner ads a day.
I'll let you do the math.

Time intervals in SQL are shown as either (start, finish) and (start,
duration) -- look up the stuff for the OVERLAPS predicate in Standard
SQL.


See, I'm not talking about time intervals, you are.

Jul 20 '05 #13
>> Serving them has no duration, no. And we serve (and record the
serving) of over 14 million banner ads a day. <<

Perhaps I do not understand what "serving" means; can you give me a
scenario. I am a customer; I want to run a banner ad. My banner
needs to be up from Christmas to New Years day. It needs to run
between 0600 UTC to 1200 UTC everyday, and it is 5 seconds long. What
are you recording so that I get the exposure for which I am paying?
Jul 20 '05 #14
On 4 Jun 2004 12:25:52 -0700, --CELKO-- wrote:
Serving them has no duration, no. And we serve (and record the

serving) of over 14 million banner ads a day. <<

Perhaps I do not understand what "serving" means; can you give me a
scenario. I am a customer; I want to run a banner ad. My banner
needs to be up from Christmas to New Years day. It needs to run
between 0600 UTC to 1200 UTC everyday, and it is 5 seconds long. What
are you recording so that I get the exposure for which I am paying?


I should let Greg explain it himself, but I can't seem to hold myself back
....

The duration you describe would be just what is needed to select at any
given instant which ad(s) should be active. However, once the ad has been
selected and HTML has been emitted to have it appear on the page, the
instant that it was emitted will be recorded in the database. A time
instant, not a duration.
Jul 20 '05 #15

"--CELKO--" <jc*******@eart hlink.net> wrote in message
news:18******** *************** ***@posting.goo gle.com...
Serving them has no duration, no. And we serve (and record the

serving) of over 14 million banner ads a day. <<

Perhaps I do not understand what "serving" means; can you give me a
scenario. I am a customer; I want to run a banner ad. My banner
needs to be up from Christmas to New Years day. It needs to run
between 0600 UTC to 1200 UTC everyday, and it is 5 seconds long. What
are you recording so that I get the exposure for which I am paying?


Banners don't have a duration. (Well, active content do, but let's come
back to that.).

So, given the criteria you've given, we'd charge you probably (and this
varies but for this we simplify) on number of impressions. I.e the number
of times it's been served.

So an end user goes to a page on our site. The code (generally ASP) goes to
a DB table and queries "what banner should I show." (there may be more than
one scheduled for say the top position on the page). A "coin flip" is made
and the DB hands back a URL to the banner in question. At that point it
records in the database that your banner was served.

Now, the end user may spend 10 seconds at that page or 10 minutes. At that
point we don't really care (and have limited ways of knowing anyway since
the web is generally stateless). You're not paying for that, you're paying
for impressions served.

Now, a standard banner is generally just a gif file, or perhaps an animated
gif. Active content may be fancier, like a flash ad (yuck) or Quicktime,
etc. But again, we don't record any of that, simply the time that the
banner was handed to the user.

This is fairly standard in terms of how banner ads are served. So, no
duration, simply an impression.

Jul 20 '05 #16
>> Banners don't have a duration. (Well, active content do, but let's
come
back to that.) <<

Isn't that content and its duration what the buyer is paying for?
we'd charge you probably on number of impressions. I.e the number of times it's been served. <<

I understand billing by the number of hits. But if you can put 1000
impressions of my ad in banner in one minute, I am not as happy as I
would be having them spaced out and retained at lest long enough for a
human being to read. When I record the hits, I record them in a time
slot -- you can only hit the banner when it is displayed.
So an end user goes to a page on our site. The code (generally

ASP) goes to
a DB table and queries "what banner should I show." A "coin flip" is
made
and the DB hands back a URL to the banner in question. At that point
it
records in the database that your banner was served. Now, the end
user may spend 10 seconds at that page or 10 minutes. <<

At that point, I don't care; the user has left the banner and is in
the target URL. I then have to model his URL behavior in a new set of
tables.

But has happened back at the banner, which is what I was modeling? I
hope the banner was there for a duration greater than zero time units.
When my time slot of duration (t1) was used up, can I assume another
banner got a time slot of (t2) in that banner? You do not "machine
gun" banners so fast that they are not readable.

What you are saying is that "the half of the fact" you see is like a
shipping clerk -- packages only leave in his world view. Likewise a
receiving clerk only sees packages arriving in his world view. But
the whole fact is that package makes a trip that takes time until it
arrives someplace (or is declared lost in transit). The correct model
is global, not local.
Jul 20 '05 #17

"--CELKO--" <jc*******@eart hlink.net> wrote in message
news:18******** *************** ***@posting.goo gle.com...
Banners don't have a duration. (Well, active content do, but let's come
back to that.) <<

Isn't that content and its duration what the buyer is paying for?
No, since duration can't be measured via the web since it's stateless.

we'd charge you probably on number of impressions. I.e the number
of times it's been served. <<

I understand billing by the number of hits. But if you can put 1000
impressions of my ad in banner in one minute, I am not as happy as I
would be having them spaced out and retained at lest long enough for a
human being to read. When I record the hits, I record them in a time
slot -- you can only hit the banner when it is displayed.

Because that's all we can know.

But has happened back at the banner, which is what I was modeling? I
hope the banner was there for a duration greater than zero time units.
When my time slot of duration (t1) was used up, can I assume another
banner got a time slot of (t2) in that banner? You do not "machine
gun" banners so fast that they are not readable.

Banners are delivered as often as the clicks the page. If they go to a
page, read the page, walk away and come back 3 weeks later, the same banner
is still displayed. If they go to a page, quickly see it's not what they
want and click a link to another page, then they'll get a different banner.

You may HOPE the banner was there for duration greater than zero time units,
but generally the web doesn't work that way.

What you are saying is that "the half of the fact" you see is like a
shipping clerk -- packages only leave in his world view. Likewise a
receiving clerk only sees packages arriving in his world view. But
the whole fact is that package makes a trip that takes time until it
arrives someplace (or is declared lost in transit). The correct model
is global, not local.


No it's not. That may be what you want it to be, but that's not the way
banner traffic works.

Jul 20 '05 #18
Greg D. Moore (Strider) (mo************ ****@greenms.co m) writes:
So an end user goes to a page on our site. The code (generally ASP)
goes to a DB table and queries "what banner should I show." (there may
be more than one scheduled for say the top position on the page). A
"coin flip" is made and the DB hands back a URL to the banner in
question. At that point it records in the database that your banner was
served.


But, of course, at my end, I am running a banner-filter proxy, so I never
see the bastard anyway. :-)

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #19
>> Banners are delivered as often as the clicks the page. If they go
to a page, read the page, walk away and come back 3 weeks later, the
same banner is still displayed. If they go to a page, quickly see
it's not what they want and click a link to another page, then they'll
get a different banner. <<

I would make a big distiction between the banner (the thing that leads
to my Christmas sale) and the image of the banner that has presisted
for weeks after the holidays in the local storage of a particular
machine. My contract was for a duration (Christmas season) and was
with the website that offered to run my banner. They were to display
from one date to another. If it got clicked (n) times between
December 01 and December 25, then I owe them according to some
formula. Maybe if the click leads to sale between December 01 and
December 25, then I owe them according to another formula. But
outside that (possibly open ended) duration, there is no obligation.

Years ago in Los Angeles, I worked on a data model for a cable TV
shopping network for a major department store chain. This was even
worse because each time a commerical played, we had to compute the
actor's residuals, the assorted union pay rates, and how to credit the
purchase to the nearest local store, and the right department within
that store. Arrgh!
Jul 20 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2933
by: Vorpal | last post by:
Here is a small sample of data from a table of about 500 rows (Using MSSqlserver 2000) EntryTime Speed Gross Net ------------------ ----- ----- 21:09:13.310 0 0 0 21:09:19.370 9000 NULL NULL 21:09:21.310 NULL 95 NULL 21:10:12.380 9000 NULL NULL 21:10:24.310 NULL 253 NULL
41
3979
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and Y contains all the elements that are B but not in A. Z will then have the elements that are in both A and B. One way of doing this is of course to iterate throug the lists and compare each of the element, but is there a more efficient way? ...
2
4200
by: Bung | last post by:
Hi, I am not really familiar with MS ACCESS. However, I am trying to make some reports where you compare current data from a table with old data from the same table. What I'm saying is we have a database with current data, and the same database with old data. I need to create reports for new rows inserted, deleted rows, and updates rows. I'm having trouble figuring how to query which rows have been updated (meaning the primary...
0
1695
by: laxmiuk | last post by:
I've original version of a table called PMM (Product Material Master). Thro' a web interface, user can change that table contents. Once changed, i need to raise an ECN (Engineering CHange Note) specifying what changes happened to original PMM table whether rows are deleted, new rows are added or existing rows are modified etc. I've both old and new version of PMM tables. The difference between two PMM tables are captured in a third table...
17
3040
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). I have a dataset as follows (1 week to keep it short): Employee 1 - Date 1 Employee 1 - Date 2
0
3771
by: varac | last post by:
Hi list, I am new to mysql and would appreciate any advice that you have to offer. I am attempting to batch insert 100 rows into a table, and I need to know the 100 id's of all the inserted rows. I know that I can find the id of the last inserted row despite my app being multi-threaded, since the select last inserted command is connection-specific.
2
2955
by: Beliavsky | last post by:
How can I replace multiple consecutive spaces in a file with a single character (usually a space, but maybe a comma if converting to a CSV file)? Ideally, the Python program would not compress consecutive spaces inside single or double quotes. An inelegant method is to repeatedly replace two consecutive spaces with one.
1
1591
by: Mike | last post by:
Hi All, I'm using vb.net as my codebehind lang. and the following code is being executed in my aspx.vb page to stamp a DB row. Dim oStatsInfo As New StatsInfo(CartID, Batch, Set, Num, 0, 0, 0, 1, 0, 1) Dim oStatsStamp As New Stats(_DataSource, oStatsInfo) Dim tStamp As New Threading.Thread(AddressOf oStatsStamp.StampStatsList)
3
1267
by: emeped | last post by:
I am using C#.NET 2003. Please I want to know if it is possible and how to insert the same data into 2 or more consecutive rows in a datatable column, at the same time, by a single click of a button. Data will be from a textbox bound to the column. Thanks.
0
9903
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9525
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7083
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5946
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.