簡體   English   中英

使用模式搜索Json(MYSQL Regex)

[英]Search on Json with patterns (MYSQL Regex)

我有一個proyect問題...就像實驗或idk ...這是一個帶有Json的關系數據庫,就像表單的響應一樣

就像是

Select details from mytable where id = 1

我得到這樣的東西

{
   "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."
   }
}

他們希望我創建一個“喜歡”查詢以了解類似

Select id from mytable where details like '"servicios":%"1":"1"%"2":"2"%"3":"4"%"4":"7"'

(該查詢不能順便說一下...)

首先看起來很簡單,但是您注意到“標量”的東西了嗎? 有時他們對我說:那個元素不在價值上,在關鍵上,但我們不確定它通常在哪里,所以您需要向我們展示

那就是為什么我來這里,因為我花了1周的時間嘗試(我解決了獲取所有表並在php上創建函數的問題,但現在他們希望使用mysql ...)

請幫我

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM