473,671 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(entr ytype, 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 3076

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

Similar topics

1
1798
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 either entering in a range(ie, 3-9), a comma separated list(ie, 3,4,5,6) or a range by start and end date(ie, yyyy-MM-dd - yyyy-MM-dd)which is a javascript calendar widget. Date_purchased is stored in the DB as 2005-04-12 13:19:13. This first...
2
47851
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 hours are available between the hours of 09.00 and 17.30 so a user can see at a glance how many hours they have unbooked on a particular day (i.e. 8.5 hours less the time of any bookings on that day), can this be done with a query or do I have to...
1
1014
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 server work that's being done. Sort of like when you go to windows update page, click on scan for updates, and the screen refreshes to show the percentage it's done scanning your computer for updates Any ideas on how this can be accomplished. Any...
12
1674
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 table will typically have 1-5 million rows. I know that the obvious "select count(*), sum(size) ..." is not a good idea, and we have seen the impact such a query has on performance. Then we tried creating triggers to maintain a table with...
10
4585
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 these keys and after AD these keys, but I need make this in one stored procedure but show problems when run this. I can make this in one stored procedure? This is the estored procedure
2
9016
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: http://fs.sdsu.edu/kf/vorb/test.php Because I print the X axis labels (time) at 90 degrees, I have to manually set the bottom margin, which forces me to set the left margin too, which used to be automatically set.
3
1807
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 whether I should use setTimeout() or setInterval(). One of the advantages I can see with using setInterval(), is that if JavaScript is disabled, and then re-enabled, the setInterval() resumes from where it left off. Can anyone confirm this for other...
6
2915
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 ipString As String
8
8747
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: 1 X1866246100 i22222 2011-03-07 05:59:37.863 2 X1884627200 K33333 2011-03-07 06:03:35.740 3 X1878488900 d44444 2011-03-07 06:04:10.520
0
8914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
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...
1
8598
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7433
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...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4224
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2810
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
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
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.