Compare 2 columns, then perform action on another column in MySQL -
i have table named tablex
in mysql. there 4 columns in tablex
. columns columncompare_now
, columncompare_past
, columnnumber_now
, columnnumber_past
.
i want write mysql statement has next logic;
if columncompare_now == 'actionneeded' , columncompare_past == 'actionneeded', columnnumber_now = `columnnumber_now` + `columnnumber_past`
mysql knowledge limited simple select statements. how can above operation implemented in mysql? meanwhile, seek figure out myself while waiting help fellow members of stackoverflow.
i'm not sure know you're trying accomplish. if want select new column information, can utilize case
statement:
select case when columncompare_now = 'actionneeded' , columncompare_past = 'actionneeded' columnnumber_now + columnnumber_past else columnnumber_now end columnnumber_now tablex
and if need in update
query:
update tablex set columnnumber_now = columnnumber_now + columnnumber_past columncompare_now = 'actionneeded' , columncompare_past = 'actionneeded'
mysql
No comments:
Post a Comment