skip to Main Content

i’m just learned how to make database here. So i have a project to make database for item inventory and i’m using phpmyadmin. I’m struggling to add values in two columns.

So i have this table:

quantity jumlah_masuk  jumlah_keluar  saldo_akhir
-------  ------------  ------------   -----------
 100          50           25            125

i want value in column “quantity” is add by value in column “jumlah_masuk” and minus by value in column “jumlah_keluar” then the result will be in column “saldo_akhir”

i’m really dont know what i’m doing here, hopefully anyone can help me with my problem. Every single answer will be appriciated it. Thank you

2

Answers


  1. I’m not used to phpmyadmin as well.But from my reading can conclude MySQL = phpmyadmin. Please try below and let me know the outcome.

    SELECT quantity,
           jumlah_masuk,
           jumlah_keluar,
           (quantity+jumlah_masuk)-jumlah_keluar AS saldo_akhir 
          from 'your_database_name_here'
    

    Regards

    Login or Signup to reply.
  2. You can use the following query to insert data:

    INSERT INTO test_table(
      quantity,
      jumlah_masuk,
      jumlah_keluar,
      saldo_akhir)
    VALUES (100,50,25,((100+50)-25));
    

    You can use the following query to retrive data:
    Note: the following query gives you perfect result if you want to use calculation on only SELECT statement

    SELECT
      quantity,
      jumlah_masuk,
      jumlah_keluar,
      ((quantity+jumlah_masuk)-jumlah_keluar) AS saldo_akhir
    FROM
      test_table;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search