如何在行/列中查询数据

时间:2019-07-05 20:26:18

标签: mysql sql

我需要在单数列中查询数据以获取特定值(电阻和负电阻)

例如仅排序包含电阻和negative_resistance的值

uid             timestamp           data        user_timestamp
209 "2019-04-05 02:23:22"   "{""ui_state"": 8}" "2019-04-04 19:23:21"
209 "2019-04-05 02:25:33"   "{""ui_state"": 8}" "2019-04-04 19:25:33"
209 "2019-04-05 02:21:56"   "{""ui_state"": 40, ""resistance"": 2854, ""negative_resistance"": 2854, ""positive_resistance"": 3281}"    "2019-04-04 19:21:55"
209 "2019-04-05 02:21:56"   "{""ui_state"": 40, ""resistance"": 2851, ""negative_resistance"": 2851, ""positive_resistance"": 3289}"    "2019-04-04 19:21:55"
209 "2019-04-05 02:21:56"   "{""ui_state"": 40, ""resistance"": 2848, ""negative_resistance"": 2848, ""positive_resistance"": 3309}"    "2019-04-04 19:21:56"

目标:我想要一条SQL Query语句来索引并选择包含“ resistance”和“ negative_resistance”值的数据

编辑:在这里找到解决方案:LIKE vs CONTAINS on SQL Server

谢谢大家的帮助

1 个答案:

答案 0 :(得分:0)

不幸的是,我不知道mysql。我在T-sql中进行了以下代码测试,它正确地识别了变量同时具有无前缀和负电阻的电阻的情况。

  

声明@mystr nvarchar(255)='“ resistance”:2854,“ negative_resistance”:2854,“ positive_resistance”:3281}“” 2019-04-04 19:21:55“'

     

当@mystr喜欢'%[^ _] resistance%'时选择大小写          和@mystr像'%negative_resistance%',然后1 else 0结尾

     

set @mystr ='“ negative_resistance”:2854,“ positive_resistance”:3281}“”“ 2019-04-04 19:21:55”'

     

当@mystr喜欢'%[^ _] resistance%'时选择大小写          和@mystr像'%negative_resistance%',然后1 else 0结尾