gpt4 book ai didi

MySql判断字符串列表中的所有元素是否存在于其他字符串列表中

转载 作者:行者123 更新时间:2023-11-29 10:33:34 24 4
gpt4 key购买 nike

我有这些表:

category_table
+--------+-----------------+---------+
| id | title | parent_id |
+--------+---------------+-----------+
| 1 | f | null |
| 2 | h | null |
| 3 | j | 1 |
| 4 | y | 3 |
| 5 | d | 3 |
+--------+-----------------+---------+

post_table
+--------+---------------+-------------+
| id | title | categoryies |
+--------+---------------+-------------+
| 1 | title1 | 1 |
| 2 | title2 | 1,2 |
| 3 | title3 | 4,5 |
| 4 | title4 | 4 |
| 5 | title5 | 3 |
+--------+---------------+-------------+

以及一个查找所有具有'3,5,2'类别的帖子的过程。

程序如何在其他字符串列表中搜索字符串列表,类似于:

Create Procedure post_select(IN category_ids Varchar(200))
Begin
Select *
From post
Where
// all category_ids exists in post categories column
// such as FIND_IN_SET('1', '1,2,3') but first parameter
// should be list string for example:
// FIND_IN_SET('2,3,4','2,4,5,6,7,8')

End;

最佳答案

您应该考虑创建一个 post_category 表,将 post_id 与 Category_id 一起存储。

关于MySql判断字符串列表中的所有元素是否存在于其他字符串列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46932554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com