Home > Database > Mysql Tutorial > body text

快速对调MySQL字段里面的某些列_MySQL

WBOY
Release: 2016-06-01 13:52:17
Original
1033 people have browsed it

  问题:表 t 有个字段叫做 c,现在想要把 c 里面的第 10 和 第 11 列位置对调一下,咋办啊?

  答案:用下面的办法吧,不过本例只对ascii字符有作用,中文或其他的就另外想办法。

  mysql>set@pos1=10;<br>  mysql>set@pos2=11;<br>  mysql>UPDATEtSETc=CONCAT(<br>  LEFT(c,@pos1-1),--第10列以前的值<br>  SUBSTR(c,@pos2,1),--第11列的值<br>  SUBSTR(c,@pos1+1,@pos2-@pos1-1),--第10到第11列之间的值<br>  SUBSTR(c,@pos1,1),--第10列<br>  RIGHT(c,LENGTH(c)-@pos2));--第11列之后的值

  其实很简单的吧 :)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!