How MySQL accesses a data table to sort output by a field

Source: Internet
Author: User

You may sometimes encounter the need to classify the data of a table in a database according to a field in that table, such as a data table area as follows

We need to sort out the area in the Serialize field, for example, in this form:

Areas Serialize

Ah blue, Ai Shayun A

Chongqing Forest, Heritage home C

Red House community, Seaman's Village H

.........

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

, GROUP by implementation,

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

You can get the data sheet above

The Group_concat (area) Here is based on the group by serialize the same category (a\b\c) data, separated by commas, such as "Red House community, Seamen's Village" ...

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

How MySQL accesses a data table to sort output by a field

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.