当前位置:网站首页>MySQL复习资料(附加)case when
MySQL复习资料(附加)case when
2022-06-29 03:42:00 【红目香薰】

MySQL复习资料(附加)case when
文章链接
本章内容:case when的使用
/*
Navicat Premium Data Transfer
Source Server : rm-bp1zq3879r28p726lco.mysql.rds.aliyuncs.com_3306
Source Server Type : MySQL
Source Server Version : 50732
Source Host : rm-bp1zq3879r28p726lco.mysql.rds.aliyuncs.com:3306
Source Schema : mytest
Target Server Type : MySQL
Target Server Version : 50732
File Encoding : 65001
Date: 28/06/2022 18:58:48
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`createDate` datetime(0) NOT NULL,
`userName` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`passWord` varchar(36) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`age` int(3) NOT NULL,
`phone` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`introduce` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `userName_index`(`userName`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES (1, '2022-06-26 13:43:11', 'admin', '123456', 22, '15912345678', '喜欢学习.');
INSERT INTO `users` VALUES (2, '2022-06-26 13:43:11', 'zhangsan', '123456', 32, '15912345678', '喜欢做饭.');
INSERT INTO `users` VALUES (3, '2022-06-26 13:43:11', 'lisi', '45451', 42, '15912345678', '喜欢化妆.');
INSERT INTO `users` VALUES (4, '2022-06-26 13:43:11', 'zhaoliu', '2222', 52, '15912345678', '喜欢武术.');
INSERT INTO `users` VALUES (5, '2022-06-26 13:43:11', 'zhaoliu', '11111', 16, '15912345678', '喜欢舞蹈.');
INSERT INTO `users` VALUES (6, '2022-06-26 13:43:11', 'zhaoliu', '123787', 27, '15912345678', '喜欢泡妞.');
SET FOREIGN_KEY_CHECKS = 1;
测试:
直接无符号判断
select userName,
(
case
when sex=0 then '女'
when sex=1 then '男'
end
) sexName
from users;
有符号判断
select userName,age,
(
case
when age<20 then '青少年'
when age<30 then '青年'
else '壮年'
end
) state
from users创建视图,并针对视图查询
#查询并创建视图
create view newTableName as (
select userName,age,
(
case
when age<20 then '青少年'
when age<30 then '青年'
else '壮年'
end
) state
from users
);
select state '状态',count(state) '数量'
from newTableName GROUP BY state;注意勤加练习啊。
边栏推荐
- 《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作
- SSH login without password
- [data update] NPU development data based on 3568 development board is fully upgraded
- Ugui slider minimum control
- 【TcaplusDB知识库】TcaplusDB-tcaplusadmin工具介绍
- logstash启动过慢甚至卡死
- 87.(cesium篇)cesium热力图(贴地形)
- 泠静的想一想自己的路
- An annotation elegant implementation of interface data desensitization
- 【TcaplusDB知识库】修改业务修改集群cluster
猜你喜欢
![[interview guide] AI algorithm interview](/img/00/918608afe7f2b8e4fd89770b512b41.png)
[interview guide] AI algorithm interview

4种分布式session解决方案

Common methods of JS date and time

88. (cesium chapter) cesium aggregation diagram
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)

87. (cesium chapter) cesium thermal map (pasted with terrain)

Mobaihe box, ZTE box, Migu box, Huawei box, Huawei Yuehe box, Fiberhome box, Skyworth box, Tianyi box and other operators' box firmware collection and sharing

Do you feel confused when you study at three in the morning?

An annotation elegant implementation of interface data desensitization

How to understand MySQL indexes?
随机推荐
使用roslaunch为Gazebo加载自定义模型时黑屏、报错问题
5-minute NLP: summary of time chronology from bag of words to transformer
Whose encryption key is written in the code? (that's you)
Draft competition process of Intelligent Vision Group
SQL performance optimization is really eye popping
Mobileone: the mobile terminal only needs 1ms of high-performance backbone
The efficiency of 20 idea divine plug-ins has been increased by 30 times, and it is necessary to write code
Data collection and management [15]
Input input box click with border
High performance current limiter guava ratelimiter
seekbar 自定义图片上下左右显示不全 / bitmapToDrawable / bitmapToDrawable互转 / paddingStart/paddingEnd /thumbOffset
Deeply analyzing the business logic of "chain 2+1" mode
Modstart rewrite rule
Ugui slider minimum control
Same tree [from part to whole]
Data collection and management [8]
Access 500 error after modstart migrates the environment
【面试指南】AI算法面试
Grafana Getting Started tutorial
Error: schema validation failed with the following error: the data path '' should not have other properties (projects)