•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 423,850 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,833 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 429 | Replies: 2
![]() |
•
•
Join Date: Dec 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I've a table named [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
thx in advance
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
thx in advance
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
select idtransaction, customerID,debit, credit, (debit - credit) as balance, transDate from transaction where customerID='Cust001' ? Is that what you are talking about ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Dec 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
nav33n nope dude,
I've come across with this Oracle Queries
, i've just dont know how analytic function could be implemented in MySql special the OVER() function or AKA Ranking function
I've come across with this Oracle Queries
sum(amount) over (order by idtransaction
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Removing Query Strings (ASP.NET)
- Double MySQL Query (PHP)
- Dynamic Query (JSP)
- MySQL nested query / joined query conversion help (MySQL)
- problem with lengthy query (Java)
- Retreiving variables from a sql query into a form (PHP)
- Sql Query (VB.NET)
- Query Building (Database Design)
Other Threads in the MySQL Forum
- Previous Thread: SQL - questions .
- Next Thread: code to transfer data from mysql to excel sheet



Linear Mode