我在 mysql 中有一个包含 2 列的表:id(auto_increment) 和 value(int 0/1)。我想用 PHP 查找表中有多少匹配模式“101”。示例:
id | value ---------- 1 | 1 2 | 1 -- 3 | 0 | => (1) 4 | 1 -- 5 | 0 | => (2) 6 | 1 -- 7 | 0 8 | 0 9 | 1 10 | 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/