gpt4 book ai didi

php - 使用 php 在一些 mysql 行中查找模式

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:33 26 4
gpt4 key购买 nike

我在 mysql 中有一个包含 2 列的表:id(auto_increment) 和 value(int 0/1)。我想用 PHP 查找表中有多少匹配模式“101”。示例:

id | value----------1  |   12  |   1   --3  |   0    |  => (1)4  |   1   --5  |   0     | => (2)6  |   1   -- 7  |   08  |   09  |   110 |   1.. |   .... |   ..5000 |  1  --5001 |  0    |  => (n)5002 |  1  --5003 |  1...  |  ...

使用数组比通过mysql查找模式(将mysql的值导入数组)更快?

有人知道如何使用 PHP 查找整行中“101”的出现次数吗?

谢谢- jack -

最佳答案

以下是您可以在 SQL 中执行此操作的方法。

select count(*) match_count
from TheTable t1
join TheTable t2 on t1.id+1 = t2.id
join TheTable t3 on t1.id+2 = t3.id
where t1.value = 1 and t2.value = 0 and t3.value = 1

关于php - 使用 php 在一些 mysql 行中查找模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18679426/

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