gpt4 book ai didi

MySQL 多个 Like 条件并在匹配时添加到计数器

转载 作者:行者123 更新时间:2023-11-29 19:19:00 25 4
gpt4 key购买 nike

我有以下 Mysql 查询,我想向其中添加一个计数器,用于显示每行的匹配数。

select id, selection
FROM tablename
WHERE (selection LIKE '%13%' OR selection LIKE '%17%' OR
selection LIKE '%19%' OR selection LIKE '%73%')

最终目标是输出每行的计数并过滤只有 2 个或更多匹配项的结果。

以下是表中的示例数据:

id - 选择

1 - 3,5,19,23

2 - 13,17,34,45

我正在寻找的是返回一个结果集,其中包含至少有 2 个数字的所有行以及其中有多少行匹配

例如:

id - 选择 - 计数

4 - 13,17,26,56 - 2

56 - 13,17,19,40 - 3

105 - 12,17,24,73 - 2

有人可以帮我修改这个特定的查询吗?谢谢:)

最佳答案

我认为您期待这样的代码


Select id, COUNT(*) as count from (select id,selection
FROM Test
WHERE (selection LIKE '%13%' OR selection LIKE '%17%' OR
selection LIKE '%19%' OR selection LIKE '%73%')
group by id,selection) t group by id having COUNT(*) >= 2

关于MySQL 多个 Like 条件并在匹配时添加到计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42528257/

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