0

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

编号 | 价值
----------
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
... | ...

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

任何人都知道如何使用 PHP 在整行中找到多少个“101”?

谢谢-杰克-

4

1 回答 1

3

以下是您可以在 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
于 2013-09-08T01:36:56.150 回答