sql - Mysql - Money transfer: Transfer data from one field to another in the same table -
i need simulate money transfer 1 account another. table looks this:
create table new_table (id int not null auto_increment, name varchar(50) not null, password varchar(50) not null, dollars double, primary key (id) );
i can't figure out statement in mysql transfer data 1 cell/field (dollars) another. has add transferred amount cell , withdraw same amount cell transfer made from.
you nay want select , update , these operations in 1 transaction. did not provide information framework/library use, not able tell how exactly...
but need set @payers_money= select dollars new_table name = 'name of paying person'; set @receivers_money=select dollars new_table name = 'name of receiving person'; set @payment=10; -- example set @payers_money=@payers_money-@payment; set @receivers_money=@payers_money+@payment; update new_table set dollars =@payers_money name= 'name of paying person'; update new_table set dollars = @receivers_money name= 'name of person being paid';
Comments
Post a Comment