[英]Search on Json with patterns (MYSQL Regex)
i having problems with a proyect... it's like a experiment or idk... It's a Relational database with Json on it like a response of a form 我有一个proyect问题...就像实验或idk ...这是一个带有Json的关系数据库,就像表单的响应一样
It's like 就像是
Select details from mytable where id = 1
and i get something like this 我得到这样的东西
{
"altitud":"1253,m.s.n.m",
"tipo_vacacion":[
"1"
],
"ubicacion":{
"scalar":"1"
},
"area":{
"scalar":"800"
},
"huespedes":{
"scalar":"4"
},
"acompanamiento":{
"scalar":"1"
},
"departamento":{
"scalar":"26"
},
"municipio":{
"scalar":"Socorro"
},
"direccion":{
"scalar":"Carrera....Calle"
},
"encargado":{
"scalar":"Hernando Marquez"
},
"encargado_telf":{
"scalar":"3158895585"
},
"traslado_km":{
"scalar":"0"
},
"traslado_tiempo":{
"scalar":""
},
"acceso_inmueble":{
"0":"0"
},
"clima":{
"scalar":"1"
},
"servicios":{
"0":"0",
"1":"1",
"2":"2",
"3":"4",
"4":"7",
"5":"8"
},
"actividades":{
"scalar":"Cocina, Hamacas, Caminatas por el jard\u00edn, Retiros de Silencio."
},
"cultura":{
"scalar":"Museo Casa de la Cultura del Socorro.\r\nTeatro Municipal, Catedral."
},
"ecodestinos":{
"0":"1",
"1":"10",
"2":"11"
},
"cobertura_celular":{
"0":"0",
"1":"1",
"2":"2",
"3":"3"
},
"seguridad":{
"0":"41",
"1":"41",
"2":"41",
"3":"41",
"4":"41"
},
"matricula":{
"scalar":"000000000000"
},
"una_semana":{
"scalar":"0"
},
"medio_mes":{
"scalar":"1"
},
"recicla":{
"0":"0",
"1":"1",
"2":"2",
"3":"3"
},
"energia_limpia":{
"scalar":"en Complementaci\u00f3n."
},
"manejo_aguas":{
"scalar":"En an\u00e1lisis."
}
}
They want me to create a "like" query to know something like 他们希望我创建一个“喜欢”查询以了解类似
Select id from mytable where details like '"servicios":%"1":"1"%"2":"2"%"3":"4"%"4":"7"'
(That query its not working by the way...) (该查询不能顺便说一下...)
It looks simple at first but, do you notice that "scalar" thing? 首先看起来很简单,但是您注意到“标量”的东西了吗? and sometimes they say to me: That element it's not on the value, its on the key, but we are not sure where is it normally so, you need to show us both
有时他们对我说:那个元素不在价值上,在关键上,但我们不确定它通常在哪里,所以您需要向我们展示
Thats why i come here, cuz i spend 1 week trying (i solved that problem getting all the table and creating a function on php but now they want it with mysql...) 那就是为什么我来这里,因为我花了1周的时间尝试(我解决了获取所有表并在php上创建函数的问题,但现在他们希望使用mysql ...)
Please, help me 请帮我
Try this: 尝试这个:
SELECT * FROM `mytable`
WHERE `details` REGEXP
'"servicios":\{[ [.newline.]]*"0":"0",[ [.newline.]]*"1":"1",[ [.newline.]]*"2":"2",[ [.newline.]]*"3":"4",[ [.newline.]]*"4":"7",[ [.newline.]]*"5":"8"[ [.newline.]]*\}'
http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.