The UDF repository for MySQL is a community project that aims to offer an organized collection of open source MySQL user defined functions.
MySQL UDFs offer a powerful way to extend the functionality of your MySQL database. The UDFs on this site are all free: free to use, free to distribute, free to modify and free of charge, even for commercial projects.
Sono un ingegnere informatico libero professionista e mi occupo della progettazione e di implementazione di soluzioni CRM per le PMI. Offro consulenza sia tecnica e quindi di sviluppo moduli, modifica moduli esistenti, integrazioni di sistema, ma anche consulenza relativa alla (re)ingegnerizzazione del processo aziendale.
Thursday, October 7, 2010
Friday, October 1, 2010
Mysql cumulated sum
Sometimes we need to obtain a cumulative sum of a columns in a query. How we can do it?
Suppose you have this simple table
id|in|out
----------
1 5 0
2 0 6
3 2 0
4 3 0
5 0 4
and you want obtain the cumulative sum of the column (in+out) like this
id|in|out|sum
-------------
1 5 0 5
2 0 6 11
3 2 0 13
4 3 0 16
5 0 4 20
This following query to do this
SELECT a.id, a.in, a.out,
Suppose you have this simple table
id|in|out
----------
1 5 0
2 0 6
3 2 0
4 3 0
5 0 4
and you want obtain the cumulative sum of the column (in+out) like this
id|in|out|sum
-------------
1 5 0 5
2 0 6 11
3 2 0 13
4 3 0 16
5 0 4 20
This following query to do this
SELECT a.id, a.in, a.out,
-- this is the new column called sum
( SELECT SUM( in + out )
FROM mytable b
WHERE b.id <= a.id
( SELECT SUM( in + out )
FROM mytable b
WHERE b.id <= a.id
) AS sum
FROM mytable a
ORDER BY id
ORDER BY id
Subscribe to:
Posts (Atom)
Manage Vtiger Menu
How Manage and customize Vtiger Menu You need to modify the function getAppMenuList in the f...

-
In this post I reviewed some of the most important trading systems and financial librarys on the net. SFL Java Trading System Enviroment ht...
-
Charts are an indispensable part of any data visualization work. People can grok visual representation of data easily than a textual variet...
-
LOAD DATA INFILE can be used to read files obtained from external sources. For example, many programs can export data in ...