Skip to main content

Posts

Showing posts from October, 2010

The UDF Repository for MySQL

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.

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, -- this is the new column called sum ( SELECT SUM( in + out )   FROM mytable b   WHERE b.id <= a.id ) AS sum FROM mytable a ORDER BY id