Mysql row-to-column (split string scenario) _ MySQL

Source: Internet
Author: User
When one-to-multiple tables are not created, they are often stored in one field as separators. the cost of doing so is that they cannot be directly associated with the query in one-to-multiple tables, generally, separate queries are performed after splitting in the program. For example, how can we directly use "one-to-multiple" to store "multiple" in a field of "one" in the form of delimiters when no intermediate table is created, the cost of doing so is that the query cannot be directly associated with one-to-many requests. generally, separate queries are used in programs. For example:

How can I query the results directly using SQL statements?

You can use an sequence number table. except for consecutive IDs, the value range of IDS is determined by the number of information stored in "1.

Implement SQL:

SELECTNAME, REPLACE (SUBSTRING_INDEX (mobile, ',',. id), CONCAT (SUBSTRING_INDEX (mobile, ',',. id-1), ','), '') AS mobileFROMsquence into ss join (SELECTNAME, CONCAT (mobile, ',') AS mobile, LENGTH (mobile) -LENGTH (REPLACE (mobile, ',', '') + 1 AS sizeFROM 'user') B ON. id <= B. size

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.