Home > Database > Mysql Tutorial > mysql implements the method of merging multiple pieces of data corresponding to the same ID_MySQL

mysql implements the method of merging multiple pieces of data corresponding to the same ID_MySQL

WBOY
Release: 2016-07-06 13:32:49
Original
1298 people have browsed it

The example in this article describes the method of mysql to merge multiple pieces of data corresponding to the same ID. Share it with everyone for your reference, the details are as follows:

such as:

CREATE TABLE `c_classuser_tab` (
 `Id` int(11) NOT NULL AUTO_INCREMENT,
 `Classid` int(11) DEFAULT NULL,
 `Username` varchar(100) DEFAULT NULL,
 `studentid` varchar(100) DEFAULT NULL,
 `College` varchar(100) DEFAULT NULL,
 `Department` varchar(100) DEFAULT NULL,
 `Email` varchar(100) DEFAULT NULL,
 `Phone` varchar(100) DEFAULT NULL,
 `Status` int(11) DEFAULT NULL,
 `Remark1` varchar(100) DEFAULT NULL,
 `Remark2` varchar(100) DEFAULT NULL,
 `Remark3` varchar(100) DEFAULT NULL,
 `activateTime` datetime DEFAULT NULL,
 `joinTime` datetime DEFAULT NULL,
 `userID` int(11) DEFAULT NULL,
 `userType` int(11) 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;

Copy after login

Teachers with the same ID have multiple substitute classes, merge them,

Teacher Substitute Class

12 Class 1, Class 2

The code is as follows:

select Username , GROUP_CONCAT(Remark1 ,'') as classes from c_classuser_tab where userID= * and userType=*

Readers who are interested in more MySQL-related content can check out the special topics on this site: "A Complete Collection of MySQL Log Operation Skills", "A Summary of MySQL Transaction Operation Skills", "A Complete Collection of MySQL Stored Procedure Skills", and "A Summary of MySQL Database Lock Related Skills" 》and《Summary of commonly used functions in MySQL》

I hope this article will be helpful to everyone in MySQL database planning.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template