473,396 Members | 1,785 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,396 software developers and data experts.

analytic function queries (HELP ME PLEASE)

I've a table name [transaction]

idtransaction is my primary key

---------------- [transaction] -------------------------
idtransaction | customerID | amount | transDate

Amount is the credit or debit / they differ when amount < 0 it is credit and when amount > 0 it's debit

Sample Data
idtransaction | customerID | amount | transDate
1 | Cust001 | 200 | 12/03/07
2 | Cust001 | 200 | 12/04/07
3 | Cust001 | -100 | 12/13/07
4 | Cust001 | 500 | 12/23/07

I need to query like this: where customerID = cus001
balance = debit - credit , but for every row the it add the previous balance.


idtransaction | customerID | debit | credit | balance | transDate
1 | Cust001 | 200 | 0 | 200 | 12/03/07
2 | Cust001 | 200 | 0 | 400 | 12/04/07
3 | Cust001 | | 100 | 300 | 12/13/07
Dec 18 '07 #1
1 1350
amitpatel66
2,367 Expert 2GB
I've a table name [transaction]

idtransaction is my primary key

---------------- [transaction] -------------------------
idtransaction | customerID | amount | transDate

Amount is the credit or debit / they differ when amount < 0 it is credit and when amount > 0 it's debit

Sample Data
idtransaction | customerID | amount | transDate
1 | Cust001 | 200 | 12/03/07
2 | Cust001 | 200 | 12/04/07
3 | Cust001 | -100 | 12/13/07
4 | Cust001 | 500 | 12/23/07

I need to query like this: where customerID = cus001
balance = debit - credit , but for every row the it add the previous balance.


idtransaction | customerID | debit | credit | balance | transDate
1 | Cust001 | 200 | 0 | 200 | 12/03/07
2 | Cust001 | 200 | 0 | 400 | 12/04/07
3 | Cust001 | | 100 | 300 | 12/13/07
This is how you do it in oracle:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT idtransaction,customerid,SUM(amount) OVER(PARTITION BY customerid order by customerid ROWS BETWEEN 1 PRECEDING and CURRENT ROW) balance FROM transaction;
  3.  
  4.  
Dec 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: JP SIngh | last post by:
Hi All I am trying to write a recursive function to list the managers and his employees in a tree like sctructure Manager 1 Emp1 Emp1.1 Emp 1.2 Emp 2
2
by: Steven Burn | last post by:
..:: The Specs: MS Access 2000 (host charges extra for SQL/MySQL) MS Windows Server 2003 (prod) / MS XP SP1 (dev) ..:: The setup: The database has been setup with two tables; tblDownloads
1
by: Aaron | last post by:
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; ...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
4
by: Got2Go | last post by:
Hello Group, I have a table that has millions of records in it. About 100 records are added every 5 minutes (one per OIDID) (the sample provided below has data for 2 OIDIDs (99 and 100) And I...
5
by: EricS | last post by:
Hi, Was wondering if anyone can help. I have multiple queries in a database. The selection criteria for these queries is always a time period I want to do the analysis by. Rather than having to go...
1
by: neha02 | last post by:
Hi all, this is my first post here although i've always referred this forum for help. I am trying to design a query based on 4 queries but i'm unable to get the result i want. Please help me-...
3
by: =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?= | last post by:
Mo <Mehile.Orloff@gmail.comwrote: may be the iteration should be inside your function qryFunc ? or, return $fQuery (when no error) and then : $reponse=qryFunc($select, $from);
5
by: Anthony2oo5 | last post by:
I wrote this function about 2 years ago when I started in PHP, I haven't touched PHP since so im still not an expert, but I would like to know what people thought of it, and if was any good / secure...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
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
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...
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.