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

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

        <tfoot id='HA6CB'></tfoot>
          <bdo id='HA6CB'></bdo><ul id='HA6CB'></ul>
      2. <small id='HA6CB'></small><noframes id='HA6CB'>

        MySQL 查询在逗号分隔的字符串中查找值

        时间:2023-08-20

        <small id='kC9Zg'></small><noframes id='kC9Zg'>

        • <bdo id='kC9Zg'></bdo><ul id='kC9Zg'></ul>

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

                  本文介绍了MySQL 查询在逗号分隔的字符串中查找值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的表 SHIRTS 中有一个字段 COLORS (varchar(50)),它包含一个逗号分隔的字符串,例如 1,2,5,12,15,.每个数字代表可用的颜色.

                  I have a field COLORS (varchar(50)) in a my table SHIRTS that contains a comma delimited string such as 1,2,5,12,15,. Each number representing the available colors.

                  当运行查询 select * from shirts where colours like '%1%' 以获取所有红色衬衫(颜色 = 1)时,我还会得到颜色为灰色( = 12) 和橙色 (=15).

                  When running the query select * from shirts where colors like '%1%' to get all the red shirts (color=1), I also get the shirts whose color is grey (=12) and orange (=15).

                  我应该如何重写查询,以便仅选择颜色 1 而不是所有包含数字 1 的颜色?

                  How should I rewrite the query so that is selects ONLY the color 1 and not all colors containing the number 1?

                  推荐答案

                  经典的方法是在左右添加逗号:

                  The classic way would be to add commas to the left and right:

                  select * from shirts where CONCAT(',', colors, ',') like '%,1,%'
                  

                  但是find_in_set也有效:

                  select * from shirts where find_in_set('1',colors) <> 0
                  

                  这篇关于MySQL 查询在逗号分隔的字符串中查找值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将 CSV 文件导入 MySQL 表? 下一篇:在 MySQL 中查找重复记录

                  相关文章

                  最新文章

                • <legend id='H3gNQ'><style id='H3gNQ'><dir id='H3gNQ'><q id='H3gNQ'></q></dir></style></legend>
                • <small id='H3gNQ'></small><noframes id='H3gNQ'>

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