I have a table field stored data like this: Fashion scarf Mens plaid scarf Cashmere scarf for men Mens grey scarves Mens grey scarf
I need to take out the set of field values (no repetition of words), returns a string, the result is:
Mens fashion plaid grey scarves cashmere scarf for men (word order doesn't matter)
Could you tell me how to write SQL statements to ah?
Thank you all!!!!!!
CodePudding user response:
- if your version support JSON, you can use JSON processing, it is relatively easy to The DROP TEMPORARY TABLE IF the EXISTS t; CREATE TEMPORARY TABLE t (value varchar (500)); INSERT INTO t VALUES (' fashion scarf '), (' mens plaid scarf '), (' cashmere scarf for men '), (' mens grey scarves'), (' mens grey scarf ');
- merger keyword SELECT the @ : x=JSON_MERGE (@ x, CONCAT (' {" ', the REPLACE (value, ' ', '" : 1, "'), '" : 1}')) The FROM t, (SELECT @ : x='{}') x;
- all not to repeat the key word (need format, do the string substitution) The SELECT JSON_KEYS (@ x);
CodePudding user response:
Need not as complicated as json, SQL statements have the query to keywords, baidu you once knew