Mysql 检查表中是否存在消息中的单词

Mysql 检查表中是否存在消息中的单词,mysql,Mysql,我必须编写一个mysql查询,通过它我必须传递一条文本消息来检查消息中是否有任何单词存在于表中 Table id words 1 arse 2 ball 3 sex string=“板球是一种球拍和球类运动,两队各有11名队员,场地中心是一个22码长的长方形场地。板球运动在许多国家有1.2亿人参加,是世界上第二受欢迎的运动。[1][2][3]每一队轮流击球,试图得分,而另一队上场。每一回合都被称为一局你可以使用像这样加入: CREATE

我必须编写一个mysql查询,通过它我必须传递一条文本消息来检查消息中是否有任何单词存在于表中

Table 
id       words
 1       arse
 2       ball
 3       sex

string=“板球是一种球拍和球类运动,两队各有11名队员,场地中心是一个22码长的长方形场地。板球运动在许多国家有1.2亿人参加,是世界上第二受欢迎的运动。[1][2][3]每一队轮流击球,试图得分,而另一队上场。每一回合都被称为一局你可以使用
像这样加入

CREATE TABLE posts(id INT, post VARCHAR(1000));

INSERT INTO posts
SELECT 1, 'Cricket is a bat and ball game played between two teams of 11 players each on a field at the centre of which is a rectangular 22-yard-long pitch. The game is played by 120 million players in many countries, making it the world''s second most popular sport.[1][2][3] Each team takes its turn to bat, attempting to score runs, while the other team fields. Each turn is known as an innings ';

CREATE TABLE words(id INT, word VARCHAR(100));

INSERT INTO words
SELECT 1 , 'arse' UNION ALL SELECT 2,'ball' UNION ALL SELECT 3, 'sex';
查询:

SELECT w.word, COUNT(*) AS `occ`
FROM posts p
JOIN words w
 ON p.post LIKE CONCAT('%', w.word, '%')
WHERE p.id = 1
GROUP BY w.word
ORDER BY occ DESC;

输出:

╔═══════╦═════╗
║ word  ║ occ ║
╠═══════╬═════╣
║ ball  ║   1 ║
╚═══════╩═════╝

您可以使用
加入,就像

CREATE TABLE posts(id INT, post VARCHAR(1000));

INSERT INTO posts
SELECT 1, 'Cricket is a bat and ball game played between two teams of 11 players each on a field at the centre of which is a rectangular 22-yard-long pitch. The game is played by 120 million players in many countries, making it the world''s second most popular sport.[1][2][3] Each team takes its turn to bat, attempting to score runs, while the other team fields. Each turn is known as an innings ';

CREATE TABLE words(id INT, word VARCHAR(100));

INSERT INTO words
SELECT 1 , 'arse' UNION ALL SELECT 2,'ball' UNION ALL SELECT 3, 'sex';
查询:

SELECT w.word, COUNT(*) AS `occ`
FROM posts p
JOIN words w
 ON p.post LIKE CONCAT('%', w.word, '%')
WHERE p.id = 1
GROUP BY w.word
ORDER BY occ DESC;

输出:

╔═══════╦═════╗
║ word  ║ occ ║
╠═══════╬═════╣
║ ball  ║   1 ║
╚═══════╩═════╝