Initialize Data DROP TABLE IF EXISTS `test_01`; CREATE TABLE `test_01` ( `id` int(0) NOT NULL, `user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'User', `km` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'Subject', `fs` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'Score', `time` datetime(0) NULL DEFAULT NULL COMMENT 'time', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic; INSERT INTO `test_01` VALUES (1, '小三', '语文', '98', '2020-08-06 15:51:21'); INSERT INTO `test_01` VALUES (2, '小三', '数学', '90', '2020-07-01 15:51:25'); INSERT INTO `test_01` VALUES (3, '小三', '英语', '77', '2020-06-01 15:51:28'); INSERT INTO `test_01` VALUES (4, '小等', '英语', '78', '2020-06-01 15:51:28'); 1. Horizontal to vertical arrangement SELECT user, SUM( CASE WHEN km = "Chinese" THEN fs ELSE 0 END ) "Chinese", SUM( CASE WHEN km = "Mathematics" THEN fs ELSE 0 END ) "Mathematics", SUM( CASE WHEN km = "English" THEN fs ELSE 0 END ) "English" FROM test_01 GROUP BY user 2. Vertical to horizontal arrangement SELECT km FROM test_01 WHERE id = 1 UNION SELECT fs FROM test_01 WHERE id = 1 This is the end of this article about how to convert MySQL horizontally to vertically and vertically to horizontally. For more information about how to convert MySQL horizontally to vertically and vertically to horizontally, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed tutorial on distributed operation of jmeter in docker environment
>>: Implementation of fastdfs+nginx cluster construction
Table of contents Preface 1. Linux changes the yu...
Operating environment: MAC Docker version: Docker...
Virtualization 1. Environment Centos7.3 Disable s...
Prepare: Define a teacher table and a student tab...
Table of contents Preface 1. Preparation - Server...
Table of contents 1. Digital Enumeration 2. Strin...
describe Returns the time interval between two da...
<br />I am very happy to participate in this...
mysql-5.7.9 finally provides shutdown syntax: Pre...
This article shares the specific code of JavaScri...
1. Reasons If the system is Centos7.3, the Docker...
This article example shares the specific code for...
Table of contents Container Hierarchy The process...
Table of contents 1. Download 2. Installation 3. ...
1 What is BEM Naming Standard Bem is the abbrevia...