mysql實現合并同一ID對應多條資料的方法_Mysql

來源:互聯網
上載者:User

本文執行個體講述了mysql實現合并同一ID對應多條資料的方法。分享給大家供大家參考,具體如下:

如 :

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;

同一ID的老師有多個代課的班級,將其合并,

教師     代課班級

12         1班,2班

複製代碼 代碼如下:
select Username , GROUP_CONCAT(Remark1 ,'') as classes  from c_classuser_tab where userID= *   and userType=*

更多關於MySQL相關內容感興趣的讀者可查看本站專題:《MySQL日誌操作技巧大全》、《MySQL事務操作技巧匯總》、《MySQL預存程序技巧大全》、《MySQL資料庫鎖相關技巧匯總》及《MySQL常用函數大匯總》

希望本文所述對大家MySQL資料庫計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.