// 以id分组,把name字段的值打印在一行,分号分隔 

关键字:group_concat              separator :分隔符         CONCAT():用于将多个字符串连接成一个字符串

select  id,group_concat(name  separator  ' ; ')   from table group by id 

 

 

// 一个字段有多个参数传递进来,应该如何写。

关键字:or  (or:或者)

select *  from table where name = "参数值1"   or    name = "参数值2"

 

 

// 一个列有多个值,查询字段中是否包含某个值

   关键字:find_in_set    (find:查找)

select *  from table where find_in_set('admin',username)

 

//一个字段多个值,修改其中的一个

关键字:replace    (replace:修改  替换)

update table set username= replace(username,'原来的值’,‘新的值’)

 

//一个字段中添加新的值,使用 “ ,” 隔开

关键字 :  concat  (concat:合并多个数组;合并多个字符串)

update table set username= concat(username,    ' ,要增加的值 '   )

 

//删除指定的字段

关键字 : replace (replace : 替换  修改)

update table set username = replace(username,     '1,' ," "   )

 

参考资料:https://blog.csdn.net/Q927920568/article/details/84563529#commentBox

Logo

更多推荐