-3

I need to query data in a singular column for specific values (resistance & negative resistance)

Ex. Sort only values containing resistance & 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"

Goal: I want a SQL Query statement that indexes & selects data that contains 'resistance' & 'negative_resistance' values

EDIT: Solution found here : LIKE vs CONTAINS on SQL Server

Thank you for help everyone

Meagan
  • 7
  • 5
  • I started to answer this but your question isn't clear enough to get an answer at this point. Perhaps you could give us an example of what specifically you want returned from a query with regards to the data in your table as you have it defined in your question? – Gharbad The Weak Jul 05 '19 at 20:56
  • Unfortunately, your question isn't very clear. Have a look at [How to post a T-SQL question on a public forum](https://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/) (nevermind that it says T-SQL; it still applies here), then use the `edit` link under your question to add more content to help us help you. – Eric Brandt Jul 05 '19 at 20:59
  • this isn't a t-sql question, the OP used the `mysql` tag – Gharbad The Weak Jul 05 '19 at 21:00

1 Answers1

0

Unfortunately, i do not know mysql. I did the following code test in T-sql and it correctly identified the case when a variable has both resistance without prefix and negative resistance.

declare @mystr nvarchar(255) = '"resistance": 2854, "negative_resistance": 2854, "positive_resistance": 3281}" "2019-04-04 19:21:55"'

select case when @mystr like '%[^_]resistance%' and @mystr like '%negative_resistance%' then 1 else 0 end

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

select case when @mystr like '%[^_]resistance%' and @mystr like '%negative_resistance%' then 1 else 0 end

Pho
  • 98
  • 1
  • 9