Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7623319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:40:38+00:00 2026-05-31T04:40:38+00:00

Database: name_ allmoney Table name: MONEY +—–+——–+————+———+———+ | id | name | date |

  • 0

Database: name_ allmoney

Table name: MONEY

+-----+--------+------------+---------+---------+
| id  | name   | date       | income  | account |
+-----+--------+------------+---------+---------+
|  1  | Ann    | 01.01.2012 | 100     | 100     |
|  2  | Matt   | 02.01.2012 | 100     | 200     |
|  3  | Tom    | 03.01.2012 | 100     | 300     |
|  4  | Peter  | 04.01.2012 | 100     | 400     |
+-----+--------+------------+---------+---------+

Hello Stackoverflowers! 😉

I’m newbie for MySQL… Last week I’ve spend searchin for solution for above situation. I’m tryin to create script summing income column, but not only showing the sum of the column like

SELECT *, SUM(kasa) from MONEY GROUP BY id;

but I have to add new column called account, which has the option like my excel sheet:

accout1st row =income1+account1
accout2nd row =income2+account1
accout3rd row =income3+account2
accout4th row =income4+account3

Is there any code or possibility to create column like account in MySQL or PHP?

CREATE TABLE money (
    id INT(11) NOT NULL AUTO_INCREMENT,
    date DATE DEFAULT NULL,
    income DECIMAL(11,4) DEFAULT NULL,
    numer_kluczyka INT(11) DEFAULT NULL,
    name CHAR(255) CHARACTER SET utf8 COLLATE utf8_polish_ci DEFAULT NULL,
    za_co CHAR(255) CHARACTER SET utf8 COLLATE utf8_polish_ci DEFAULT NULL,
    account INT(11) DEFAULT NULL,
    PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:40:39+00:00Added an answer on May 31, 2026 at 4:40 am

    You can do it using a user variable –

    SELECT @m := 0;
    
    SELECT
        id,
        name,
        date,
        income,
        @m := @m + income AS balance
    FROM money
    ORDER BY date ASC, id ASC;
    

    The order by should use the primary key for the table.

    Splitting the two queries in your PHP should fix the problem –

    <?php
    
    $connection = mysql_connect('host', 'user', 'pass') or die('failed to connect');
    mysql_select_db("album", $connection) or die('failed to select db');
    
    mysql_query("SELECT @m:=0;");
    $result = mysql_query("SELECT id, imie_i_nazwisko, data_wplaty, kasa, @m := @m + income AS balance FROM money ORDER BY data_wplaty ASC , id ASC");
    
    while($row = mysql_fetch_array($result)) {
        echo $row['income'] . " " . $row['balance'];
        echo "<br />";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in my database: Name | Element 1 2 1 3
Given a model's instance object, how can I get the database table's name? I
Suppose a database table has a column Name which is defined as key for
I have a database name "CUED" (sqlite Android)it have a table HELLO which contain
I have a table in the database: name Opinion Tim Tim has an opinion
Could you tell me how to remove the database name from the table's name.
Database Name = MyDB Table Name = MyTable Column Name = ColumnSurname Using SQL
Example:i have a database name base1,with one table(product) and data inside her:productid,name,price. How to
If I know the database-name and table-name, how can I find columns-count of the
How can I edit a particular record in a SQLite table given, Database Name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.