gpt4 book ai didi

php - 如何计算从数据库检索到的逗号分隔值

转载 作者:行者123 更新时间:2023-11-29 01:26:09 24 4
gpt4 key购买 nike

我的Sql表是这样的。从表中检索数据并计算该值中的特定数据。如果给定的 no 为 6 则表示计数为 4。

+---------+-------------+-------------+
| id | Values |
+---------+-------------+-------------+
| 11 | 1,2,4,5,6 |
| 12 | 1,2,6 |
| 13 | 4,5,6 |
| 14 | 2,3,6 |
+---------+------------+--------------+

最佳答案

您可以使用find_in_set从逗号分隔的字符串中搜索值

select count(*) total
from demo
where find_in_set(6, `Values`) > 0;

Demo

关于php - 如何计算从数据库检索到的逗号分隔值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50559262/

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