Home > database >  Rookie to beg a SQL code
Rookie to beg a SQL code

Time:09-30

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

CodePudding user response:

refer to the second floor qq_29623901 response:
need not as complicated as json, SQL statements have the query to keywords, baidu once you know the

Not to search, ask more specific

CodePudding user response:

reference ZJCXC reply: 3/f
Quote: refer to the second floor qq_29623901 response:

Need not as complicated as json, SQL statements have the query to keywords, baidu once you know the

Not to search, ask more specific

Wow, bosses, still use I teach you more specific, the building Lord questions I didn't know, very detailed, the original poster is a process of how to store,
Is this:
Or like this:

CodePudding user response:

I'm not quite sure, the form of data samples with me

CodePudding user response:

Select DISTINCT substring_index (substring_index (Dr. Alue, ', ', b.h elp_topic_id + 1), ', ', 1)
The from
(select GROUP_CONCAT (REPLACE (value, "', ', ')) value from t) a
The join
Mysql. Help_topic b
On b.h elp_topic_id & lt; (length (Dr. Alue) - length (the replace (Dr. Alue, ', ', ')) + 1);

CodePudding user response:

Break up without GROUP_CONCAT first. After all, the length of the unknown, not GROUP_CONCAT is no guarantee to the number of split within the scope of the serial number of the table
GROUP_CONCAT, more bad guarantee
  • Related