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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -