Hi Everybody I'm New,
I use this forum because i am creating a program where I can register a person and how much money debt, how much pay and its total.
The idea is store it in a database.
I have can not insert the subtraction of SUM(Deuda-Abono) in the colum total in the same row, the most I could do was generate the total but duplicating the line with this may be i am wrong
INSERT INTO Clientes (Total)
SELECT SUM(Deuda-Abono)
From Clientes
Group By ID;
Here is how look my program
[url=https://prnt.sc/78g8QA3IWgsi]
This is my code when i run the boton Add, as you can see I dont insert the colum total so I think that I could do the operation and storage it in the same row with another sentence.
private void btnAgregarActionPerformed(java.awt.event.ActionEve nt evt) {
Conexion objConexion = new Conexion(); //Object and class conection
Clientes oClientes = recuperarDatosGui(); //recuperarDatosGui - retrieve the information from the database
String strSentenciaInsert = String.format("INSERT INTO Clientes(ID, Nombre, Telefono, Deuda, Abono)"
+ "VALUES (null, '%s', '%s', '%s','%s')", oClientes.getNombre(), oClientes.getTelefono(),oClientes.getDeuda(),oClie ntes.getAbono());
//HACE REFERENCIA a ---------------------------
objConexion.ejecutarSentenciaSQL(strSentenciaInser t);
this.mostrarDatos();
this.limpiarDatos();
}
Sentence to Substract:
INSERT INTO Clientes (Total)
SELECT SUM(Deuda-Abono)
From Clientes
Group By ID;
I am new Programming so if you Could help me or if you can give another idea in how i can do my program I would appreciate it.
Thanks.