gpt4 book ai didi

php - 从我的 sql 表行中搜索至少一个逗号分隔值

转载 作者:行者123 更新时间:2023-11-30 22:09:06 25 4
gpt4 key购买 nike

我想做一个查询,从表行中获取至少一个逗号分隔值匹配的结果。

就像我的自定义表具有以下值。 enter image description here

SR value are inserted 3 times so i want whenever i execute `SELECT QUERY` that will search `SR` value is inserted or not, if `SR` values inserted then do nothing else insert new row.

我使用了以下查询,但它无法提供我想要的输出。

$get_old_model = $wpdb->get_results("SELECT model_name FROM `wp_make_details` WHERE `post_id` = ".$post_id."
AND model_name LIKE '%".$modle_list."%'");

任何人都知道更多关于它的帮助我。

最佳答案

引自FIND_IN_SET function文档:

Returns a value in the range of 1 to N if the string str is in the string list strlist consisting of N substrings. A string list is a string composed of substrings separated by , characters. If the first argument is a constant string and the second is a column of type SET, the FIND_IN_SET() function is optimized to use bit arithmetic. Returns 0 if str is not in strlist or if strlist is the empty string. Returns NULL if either argument is NULL. This function does not work properly if the first argument contains a comma (,) character.

 mysql> SELECT FIND_IN_SET('b','a,b,c,d');
-> 2

您可以针对您的情况尝试以下查询:

Select model_name from `wp_make_details` where  `post_id` = ".$post_id."
AND model_name LIKE FIND_IN_SET('SR',model_name) != 0;

如果 SR 已经插入到您的表中,则此查询将返回行。

关于php - 从我的 sql 表行中搜索至少一个逗号分隔值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40714246/

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