执行在某些位置屏蔽二进制字符串的Mysql查询

时间:2016-05-28 02:24:28

标签: mysql

这个问题很难,但我正在做的是查询二进制数据来检查事件。我无法使用全文搜索,我不确定无论如何都有帮助,但我说数据库中有一个字符串,如00101(但长度为256个字符),用户试图搜索数据库1。有没有办法找到第三个位置1的所有行?另外,有没有办法通过多个位置查找来完成此操作(例如,第3和第5位的1)?

我问,因为我试图获取五个数据并将它们放在数据库的一行而不是五行。每个二进制值都是对象的布尔“出现”,因此0 `media_id` int(9) unsigned NOT NULL, `256_hash` text NOT NULL, `sequence` int(11) unsigned NOT NULL

更新

模式

media_id    palette_hash    sequence
1   00000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000    1464423415
2   00000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000    1464423415

我之前应该包含这个,但实际的256个哈希字符串长度为256个字符。我假设从长远来看它会成为一个问题,因为它不可索引。

示例记录

{{1}}

1 个答案:

答案 0 :(得分:1)

您可以使用REGEXP比较。

所有行" 1"在第三位:

#  The pattern reads: "anything twice, then 1, then anything"
SELECT * FROM rows WHERE (column REGEXP '^.{2}1.*$')

所有行" 1"在第三和第五位:

#  The pattern reads: "anything twice, then 1, then anything once, then 1, then anything"
SELECT * FROM rows WHERE (column REGEXP '^.{2}1.1.*$')