Mysql implementation merges the same ID corresponding to multiple data method _mysql

Source: Internet
Author: User

This article illustrates the MySQL implementation method that merges multiple data with the same ID. Share to everyone for your reference, specific as follows:

Such as:

CREATE TABLE ' c_classuser_tab ' (
 ' Id ' int () NOT NULL auto_increment,
 ' Classid ' int (one) DEFAULT null,
 ' Username ' varchar (MB) default null,
 ' studentid ' varchar (m) default null,
 ' College ' varchar (MB) default null ,
 ' Department ' varchar (MB) default null,
 ' Email ' varchar default NULL,
 ' Phone ' varchar ' default NULL, '
 Status ' int (one) default null,
 ' Remark1 ' varchar (MB) default null,
 ' REMARK2 ' varchar (m) default NULL,
 ' REMARK3 ' varchar (MB) default null,
 ' activatetime ' datetime default NULL,
 ' Jointime ' datetime Default NULL,
 ' UserID ' int (one) default null,
 ' usertype ' int (one) default null,
 PRIMARY KEY (' Id '),
 Key ' C_classuser_tab_index ' (' StudentID '),
 key ' Idx_classuser_complex ' (' Classid ', ' UserID ')
engine= MyISAM auto_increment=31091 DEFAULT Charset=utf8;

Teachers with the same ID have multiple substitute classes that combine them,

Teacher Substitute class

12, Class 1, Class 2.

Copy Code code as follows:
Select Username, Group_concat (Remark1, ') as classes from C_classuser_tab where userid= * and usertype=*

More information about MySQL interested readers can view the site topics: "MySQL Log operation skills Daquan", "MySQL Transaction operation skills Summary", "MySQL stored process skills encyclopedia", "MySQL database lock related skills summary" and "MySQL commonly used function large summary"

I hope this article will help you with the MySQL database meter.

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.