0

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

aynber
  • 22,380
  • 8
  • 50
  • 63
fahmi zikrul
  • 7
  • 1
  • 5
  • Please provide sample data and desired results. – Gordon Linoff Aug 03 '20 at 01:33
  • @GordonLinoff ive update my question sir, thats what i want, but it only a view, i want to insert the value on saldo in my table – fahmi zikrul Aug 03 '20 at 01:42
  • Your INSERT contains one column (`saldo`), into which you're trying to place multiple values. The error message says that pretty clearly with *column count doesn't match value count*. – Ken White Aug 03 '20 at 01:42

1 Answers1

0

Do you want to update the value:

UPDATE laporan_bukubesar
    SET saldo = (@variable := @variable + (`debit` - `kredit`))
    ORDER BY tanggal ASC;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Its work sir, thaks for helping me, i just add SET @variable = 0; at the beginning SET @variable = 0; UPDATE laporan_bukubesar SET saldo = (@variable := @variable + (`debit` - `kredit`)) ORDER BY tanggal ASC; – fahmi zikrul Aug 03 '20 at 01:45