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
You can do it using a user variable –
The order by should use the primary key for the table.
Splitting the two queries in your PHP should fix the problem –