mysql - Update Query Using strcmp result -
i unsure how change select query update.
the select query is:
select if (strcmp( `player1`, `player2` ) >0, concat(player2, " - ", player1), pair) goodpair scores
the problem trying solve pairs field contains pair names not in same order. example "bill - dennis" , "dennis - bill" same pair appear in different records , want pair names "lesser" name first can count times particular duo found.
if more info needed, let me know.
thanks in advance.
bili
you can use least , greatest functions:
select concat_ws(' - ', least(payer1,player2), greatest(player1,player2)) goodpair scores
i prefer use concat_ws concatenate strings separator instead of concat in particular case same.
to create update query, use this:
update scores set goodpair = concat_ws(' - ', least(payer1,player2), greatest(player1,player2))
if need swith player1 player2 in case player1 greater player2, use update query:
update score set player1=least(player1,player2), player2=greatest(player1,player2) player1>player2
fiddle here.
Comments
Post a Comment