1. <small id='GCoSr'></small><noframes id='GCoSr'>

      1. <i id='GCoSr'><tr id='GCoSr'><dt id='GCoSr'><q id='GCoSr'><span id='GCoSr'><b id='GCoSr'><form id='GCoSr'><ins id='GCoSr'></ins><ul id='GCoSr'></ul><sub id='GCoSr'></sub></form><legend id='GCoSr'></legend><bdo id='GCoSr'><pre id='GCoSr'><center id='GCoSr'></center></pre></bdo></b><th id='GCoSr'></th></span></q></dt></tr></i><div id='GCoSr'><tfoot id='GCoSr'></tfoot><dl id='GCoSr'><fieldset id='GCoSr'></fieldset></dl></div>
        <legend id='GCoSr'><style id='GCoSr'><dir id='GCoSr'><q id='GCoSr'></q></dir></style></legend>

          <bdo id='GCoSr'></bdo><ul id='GCoSr'></ul>
        <tfoot id='GCoSr'></tfoot>

        在 MySQL 表中搜索包含 CSV 数据的列是否存在输入值

        Searching a column containing CSV data in a MySQL table for existence of input values(在 MySQL 表中搜索包含 CSV 数据的列是否存在输入值)

        <legend id='fhw7W'><style id='fhw7W'><dir id='fhw7W'><q id='fhw7W'></q></dir></style></legend>

              <bdo id='fhw7W'></bdo><ul id='fhw7W'></ul>
              1. <small id='fhw7W'></small><noframes id='fhw7W'>

                  <tbody id='fhw7W'></tbody>
                <tfoot id='fhw7W'></tfoot>
                <i id='fhw7W'><tr id='fhw7W'><dt id='fhw7W'><q id='fhw7W'><span id='fhw7W'><b id='fhw7W'><form id='fhw7W'><ins id='fhw7W'></ins><ul id='fhw7W'></ul><sub id='fhw7W'></sub></form><legend id='fhw7W'></legend><bdo id='fhw7W'><pre id='fhw7W'><center id='fhw7W'></center></pre></bdo></b><th id='fhw7W'></th></span></q></dt></tr></i><div id='fhw7W'><tfoot id='fhw7W'></tfoot><dl id='fhw7W'><fieldset id='fhw7W'></fieldset></dl></div>

                • 本文介绍了在 MySQL 表中搜索包含 CSV 数据的列是否存在输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 MySQL 中有一个表 ITEM,它存储数据如下:

                  I have a table say, ITEM, in MySQL that stores data as follows:

                  ID    FEATURES
                  --------------------
                  1     AB,CD,EF,XY
                  2     PQ,AC,A3,B3
                  3     AB,CDE
                  4     AB1,BC3
                  --------------------
                  

                  作为输入,我会得到一个 CSV 字符串,类似于AB,PQ".我想获取包含 AB 或 PQ 的记录.我意识到我们必须编写一个 MySQL 函数来实现这一点.因此,如果我们在 MySQL 中定义了这个神奇的函数 MATCH_ANY 来执行此操作,那么我将简单地执行如下 SQL:

                  As an input, I will get a CSV string, something like "AB,PQ". I want to get the records that contain AB or PQ. I realized that we've to write a MySQL function to achieve this. So, if we have this magical function MATCH_ANY defined in MySQL that does this, I would then simply execute an SQL as follows:

                  select * from ITEM where MATCH_ANY(FEAURES, "AB,PQ") = 0
                  

                  上述查询将返回记录 1、2 和 3.

                  The above query would return the records 1, 2 and 3.

                  但是我在实现这个函数时遇到了各种各样的问题,因为我意识到 MySQL 不支持数组并且没有简单的方法可以根据分隔符分割字符串.

                  But I'm running into all sorts of problems while implementing this function as I realized that MySQL doesn't support arrays and there's no simple way to split strings based on a delimiter.

                  改造桌子是我最后的选择,因为它涉及很多问题.

                  Remodeling the table is the last option for me as it involves lot of issues.

                  我可能还想执行包含多个 MATCH_ANY 函数的查询,例如:

                  I might also want to execute queries containing multiple MATCH_ANY functions such as:

                  select * from ITEM where MATCH_ANY(FEATURES, "AB,PQ") = 0 and MATCH_ANY(FEATURES, "CDE")
                  

                  在上面的例子中,我们将得到记录 (1, 2, 3) 和 (3) 的交集,这将是 3.

                  In the above case, we would get an intersection of records (1, 2, 3) and (3) which would be just 3.

                  非常感谢任何帮助.

                  谢谢

                  推荐答案

                  首先,数据库当然不应该包含逗号分隔值,但希望您已经意识到这一点.如果表格已规范化,您可以使用如下查询轻松获取项目:

                  First of all, the database should of course not contain comma separated values, but you are hopefully aware of this already. If the table was normalised, you could easily get the items using a query like:

                  select distinct i.Itemid
                  from Item i
                  inner join ItemFeature f on f.ItemId = i.ItemId
                  where f.Feature in ('AB', 'PQ')
                  

                  可以匹配逗号分隔值中的字符串,但效率不高:

                  You can match the strings in the comma separated values, but it's not very efficient:

                  select Id
                  from Item
                  where
                    instr(concat(',', Features, ','), ',AB,') <> 0 or
                    instr(concat(',', Features, ','), ',PQ,') <> 0
                  

                  这篇关于在 MySQL 表中搜索包含 CSV 数据的列是否存在输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                • <i id='4ter4'><tr id='4ter4'><dt id='4ter4'><q id='4ter4'><span id='4ter4'><b id='4ter4'><form id='4ter4'><ins id='4ter4'></ins><ul id='4ter4'></ul><sub id='4ter4'></sub></form><legend id='4ter4'></legend><bdo id='4ter4'><pre id='4ter4'><center id='4ter4'></center></pre></bdo></b><th id='4ter4'></th></span></q></dt></tr></i><div id='4ter4'><tfoot id='4ter4'></tfoot><dl id='4ter4'><fieldset id='4ter4'></fieldset></dl></div>
                          <tfoot id='4ter4'></tfoot>

                          • <bdo id='4ter4'></bdo><ul id='4ter4'></ul>

                              <tbody id='4ter4'></tbody>
                          • <legend id='4ter4'><style id='4ter4'><dir id='4ter4'><q id='4ter4'></q></dir></style></legend>

                            <small id='4ter4'></small><noframes id='4ter4'>