赞
踩
表1:user
表2:user_total
select id,name from user where
id REGEXP (
select replace
(
(select user_ids from user_total where id = 3), ',','|'
)
)
select id,name from user where
id REGEXP (
select replace
(
(select group_concat(user_ids) from user_total where id IN (3,4,5)), ',','|'
)
)
select id,user_ids from user_total where user_ids regexp '(^|,)2(,|$)'
select id,user_ids from user_total where user_ids regexp '(2|3)'
select id,user_ids from user_total where user_ids regexp '((?=.*2)(?=.*3)^.*$)'
模式匹配操作符,说白了就是正则 ^ 匹配字符串开头 $ 匹配字符串结尾 . 匹配任意单个字符 [...] 匹配括号间的任意字符 [^...] 匹配方括号未列出的任意字符 p1|p2|p3 交替;匹配任意p1或p2或p3 * 匹配前面的元素的零次或多次 + 匹配前面的元素的一次或多次 {n} 匹配前面的元素n次 {m,n} 匹配前面的元素m至n次
replace(str,search,replace)
将str中出现的全部的search替换为replace
group_concat( [连接字段] [order by 排序字段 asc/desc ] , [ 分隔符] )
将 连接字段 根据 排序字段 的排序规则用 分隔符 连接在一起
例: group_concat(name order by id desc , ';')
注: 连接字段和排序是一体的中间无逗号,但是与分隔符之间是需要逗号分隔的
select GROUP_CONCAT(name order by id desc ,';') as names from user
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。