文章目錄
-
- 問題場景
- in 和 find_in_set的差別
- 有序比對 locate
- 無序比對 Mybatis foreach
- 我的公衆号
問題場景
現在有一張表,type,是逗号拼接存儲的。
in 和 find_in_set的差別
有序比對 locate
無序比對 Mybatis foreach
<select id="find" resultMap="resultMap" parameterType="object">
SELECT * FROM `test` where 1=1 and
<foreach item="item" collection="typeList" separator="OR" open="(" close=")" index="">
find_in_set(#{item},type)
</foreach>
</select>
# 包含1和3的都查出來了
SELECT * FROM `test` where 1=1 and ( FIND_IN_SET(1,type) OR FIND_IN_SET(3,type) )
我的公衆号
程式員進化之路,從一個簡單的公衆号開始