简体   繁体   English

MySQL选择数组值在最小值和最大值之间的行

[英]MySQL select rows with array values between a min and a max

I have this issue that i'm stuck in... 我遇到了这个问题...

I have a field like an array, values separated by space. 我有一个像数组一样的字段,值之间用空格隔开。 Let's say we have these values: 假设我们具有以下值:

v1: "100 150 200 300"
v2: "50 100"
V3: "130 230 415"
v4: "340 500 600"
...

Then i have two user input values like a min and a max, let's say 120 and 300. I need to select with mysql from table all rows that have an array value between these min and max 然后我有两个用户输入值,例如最小值和最大值,例如120和300。我需要使用mysql从表中选择所有具有这些最小值和最大值之间的数组值的行。

So the output should be v1 and v3 from the previous example. 因此,上一个示例的输出应为v1和v3。

Can someone help me, please? 有人能帮助我吗?

I completely agree with the comments saying that this is terrible design, but I think this could be solved with a function that splits your array into its respective values, combined with an APPLY. 我完全同意这种说法,这是一个糟糕的设计,但是我认为可以通过将数组拆分成各自值并结合APPLY的函数来解决。

This should then yield a table like 然后应该产生一个像

v1 100 v1 100

v1 150 v1 150

etc. 等等

v2 50 v2 50

v2 100 v2 100

etc. 等等

From there the problem should be easy. 从那里开始,问题应该很容易。

I would check this thread Split value from one field to two 我会检查此线程将值从一个字段拆分为两个

Or pull the data back and use server-side code to split the value into an array and then do the comparison. 或拉回数据并使用服务器端代码将值拆分为一个数组,然后进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM