Quick comparison of some columns in the MySQL field _ MySQL

Source: Internet
Author: User
Quickly tune certain columns in the MySQL field

Q: The table t has a field called c. Now I want to check the 10th and 11th columns in column c. What should I do?

Answer: Use the following method. However, this example only applies to ascii characters. you can find another method for Chinese characters or other characters.

Mysql> set @ pos1 = 10;
Mysql> set @ pos2 = 11;
Mysql> UPDATEtSETc = CONCAT (
LEFT (c, @ pos1-1), -- values earlier than 10th columns
SUBSTR (c, @ pos2, 1), -- Value of column 11th
SUBSTR (c, @ pos1 + 1, @ pos2-@ pos1-1), -- value between 10th and 11th columns
SUBSTR (c, @ pos1, 1), -- column 10th
RIGHT (c, LENGTH (c)-@ pos2); -- value after column 11th

In fact, it is very simple :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.