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
I want to make a docker for cron scheduled tasks ...
1. Preparation Install Tomcat on Linux system, us...
The “Cancel” button is not part of the necessary ...
1. Pull the image docker pull registry.cn-hangzho...
1. Preparation 1.1 harbor download harbor downloa...
question Question 1: How to solve the performance...
Source of the problem: If the slave server is the...
How to install Linux CentOS 7.7 system in Vmware,...
Table of contents Overview 1. useState 1.1 Three ...
Table of contents Problem Description Scenario In...
1. Make sure the network connection method is bri...
1. Use the transform attribute to display the ima...
Recently, Xiao Ming just bought a new Mac and wan...
1. Install Baidu Eslint Rule plugin npm i -D esli...
A registration page template implemented with HTM...