473,395 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

calculating aggregates over row intervals in an update

what is the best way to calculate: (in the context of an update)
the number of transactions that were entered in the same way as the
current transaction out of the 5 last transactions by the cardholder
(regardless of entry method)

or more generally stated: calculate some aggregate function over a
subset of rows from an interval of rows defined around this row, i.e.
the one being updated

the set-theory happy version:

CREATE TABLE cg (
cardnumber varchar2(16) not null,
entrytype char(1) not null,
chargedate date not null,
NBANAT5#DD0 numeric(7) null) ;

UPDATE cg
SET NBANAT5#DD0
= NVL(( SELECT COUNT(*)
FROM cg t
WHERE t.cardnumber = cg.cardnumber
AND t.entrytype = cg.entrytype
AND ( SELECT COUNT(*)
FROM cg t1
WHERE t1.cardnumber = cg.cardnumber
AND t1.chargedate >= t.chargedate
AND t1.chargedate < cg.chargedate) <= 5
AND t.chargedate <= cg.chargedate ),0) ;

so, for every single row in the transaction history for the
cardholder, it calculates how many rows exist between it and the
current transctions to determine if it is in the last 5 or not. it
works and when each cardholder has a sufficiently small transaction
history then the performance is not TOO bad, but when the transaction
history becomes long it is grotesque. (well, it's grotesque in the
first place, but the response time will change from maybe a minute
over a million rows with small transaction histories to being several
hours over a million rows with long transaction histories)

if it were legal, then the following would perform better, but it
isn't. (no correlated subquery in an in-line view, right?)

UPDATE cg1000
SET NBANAT5#DD0
= NVL(( SELECT count(*)
FROM ( SELECT * from cg t1
where t1.bank_account_number = cg.bank_account_number
and t1.chargedate < cg.chargedate
order by t1.chargedate desc) t
WHERE ROWNUM <= 5
and t.account_type = cg.account_type),0) ;

conceivable something like

SUM(decode(entrytype, this.entrytype, 1, 0) OVER (partition by
cardnumber order by chargedate desc rows between 5 preceding and 1
preceding)

would work as well, but i don't see any means of using this in the
context of an udpate statement. (can't use aggregate or analytic
functions in update statements, right?) (and several customers are
using 8i standard which i don't think has analytic functions, right?)

any suggestions?

thank you,
Wil
Jul 19 '05 #1
0 3065

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

Similar topics

1
by: MattMika | last post by:
I am trying to integrate a Credit Card # deletion option into Batch_print_center and need some help. Batch_print_center has a form where you specify orders you want to print or proccess by...
2
by: Shaun | last post by:
Hi, I have a table called Bookings which has two important columns; Booking_Start_Time and Booking_End_Time. These columns are both of type DATETIME. Given any day how can I calculate how many...
1
by: joe | last post by:
Hello A simply question which may not have a simple answer.. I would like to update an IE page at regular intervals to give clients visual feedback on say a download that there doing, or some...
12
by: jao | last post by:
I have an application with a table that tracks objects with a "size" attribute. What we want to do is to periodically report on the number of these objects and the sum of the object sizes. The...
10
by: Ivan | last post by:
Hi to all !!! I have one stored procedure that update and delete rows in differents tables, but when I try of delete of the main table this show problems with primary and foreign key. I DROP...
2
by: johnbkim | last post by:
I'm using JPGraph to plot temperature vs. time. Time is given as timestamps, so I use a callback function to print it as hours and minutes. Here's the graph and the code: ...
3
by: Daz | last post by:
Hi everyone. I have a relatively simple question which is hindered only by my lack of understanding. I am creating a clock (as if that's never been done before...), and I was stuck as to...
6
ak1dnar
by: ak1dnar | last post by:
Hi, I have created Sub in VB.net application, Which reads a text file contents. Sub IPsetter() Dim fileName As String Dim realIParray As String() = Nothing Dim...
8
by: BusterKarmul | last post by:
Hello, Is it possible to determine the Min and Max timestamp intervals for records as they are inserted (SQL Server 2005)? The table accepts inserts only (no updates) and produces this output: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.