Mysql data table is sorted out by a field _mysql

Source: Internet
Author: User

Perhaps you will sometimes encounter the need to put the data of a table in the database according to the table of a field category output, such as a data table area as follows

We need to sort out the inside area according to the Serialize field, such as this form:

Areas Serialize

Ah blue, Ai Shayun A

Chongqing Forest, Heritage home C

Red Army Building community, Seaman's Village H

.........

To be shown in this form, you can do so by using the Group_concat in MySQL ()

, GROUP by implementation,

Select Serialize,group_concat (area) as areas from the area group by Serialize;

You can get the data table above

Group_concat (area) Here is the area according to group by serialize the same category (a\b\c) of the data together, separated by commas, such as "Red Army building community, Seamen's Village" ...

So you can sort out the output, and of course you need to split the serialize (explode ()), Traverse (foreach) ...

The above mentioned is the entire content of this article, I hope you can enjoy.

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.