Search code examples
mysqlsqlsql-insertmysql-error-1136

MySQL Insert Issue : #1136 - Column count doesn't match value count at row 1


Im trying to input value of continous counting debit-kredit into saldo column, heres my sql code

I want to do debit - kredit and put in saldo column, my query above allows me to retrieve saldo values but not failed on inserting

SET @variable = 0;
-- Without Pagination
INSERT into laporan_bukubesar (`saldo`)
SELECT        `tanggal`, `debit`, `kredit`, @variable := @variable + (`debit` - `kredit`) as `saldo`
FROM          laporan_bukubesar
ORDER BY      `tanggal` ASC;

#1136 - Column count doesn't match value count at row 1

Heres my table

Heres what i want


Solution

  • Do you want to update the value:

    UPDATE laporan_bukubesar
        SET saldo = (@variable := @variable + (`debit` - `kredit`))
        ORDER BY tanggal ASC;