在SQL IN运算符中使用通配符

时间:2015-09-02 13:52:08

标签: mysql wildcard sql-in

结构:

table
c1 c2
1  test
1  test2
2  test
2  test3
3  test4

SQL:

SELECT c1 FROM table WHERE c2 in ("test3","test4")

我想要的是什么:

SELECT c1 FROM table WHERE c2 in ("%3","%st4")

我该怎么做?

2 个答案:

答案 0 :(得分:2)

<div class="hiddenHandle">
    <input type="range" name="slider-1" id="slider-1" min="1" max="9951" value="1" step="50">    
</div>
<div data-role="rangeslider" data-track-theme="b" data-theme="a">        
    <input type="range" name="range1" id="range1" disabled="disabled" min="0" max="10" value="2">        
    <input type="range" name="range2" id="range2" disabled="disabled" min="0" max="10" value="6">   
</div>

答案 1 :(得分:0)

这是我的方法,只是为了遵循你的问题中的逻辑:

http://sqlfiddle.com/#!9/aca65e/2

SELECT *
FROM `table`
WHERE c2 REGEXP '.*3$|.*st4$';

但请记住解决方案

SELECT c1 FROM table WHERE (c2 like "%3") or (c2 like "%st4")
如果c2列被编入索引,则@ splash58提供的

可能会快得多。