当前位置:网站首页>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;注意勤加练习啊。
边栏推荐
- Inventory deduction based on redis
- 基于redis实现的扣减库存
- Do you feel confused when you study at three in the morning?
- 【TcaplusDB知识库】查看tcapdir目录服务器
- Data statistical analysis (SPSS) [8]
- 需求分析说明书和需求规格说明书
- Influence of air resistance on the trajectory of table tennis
- Data collection and management [1]
- leetcode:560. Subarray with and K
- 点云地图导入gazebo思路
猜你喜欢

How to back up all data on Apple mobile phone in 2 steps (free)

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

MobileOne: 移动端仅需1ms的高性能骨干

【世界海洋日】TcaplusDB号召你一同保护海洋生物多样性

分享 60 个神级 VS Code 插件
![Zigzag sequence traversal of binary tree [one of layered traversal methods - > preorder traversal +level]](/img/f6/0df9f2a454cea0a95a5347546a90fb.png)
Zigzag sequence traversal of binary tree [one of layered traversal methods - > preorder traversal +level]

人大金仓(KingBase)导出表结构

一个注解优雅的实现 接口数据脱敏
![[tcapulusdb knowledge base] Introduction to tcapulusdb table data caching](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb table data caching

Go implements distributed locks
随机推荐
Ugui slider minimum control
微秒级 TCP 时间戳
Geth --- Error: authentication needed: password or unlock
泠静的想一想自己的路
An annotation elegant implementation of interface data desensitization
leetcode:304. 二维区域和检索 - 矩阵不可变
VIM configuration and use
88. (cesium chapter) cesium aggregation diagram
Live broadcast preview | neurips special session I & Young Scientists special session
【世界海洋日】TcaplusDB号召你一同保护海洋生物多样性
Web crawler knowledge day04
图论的基本概念
20款IDEA 神级插件 效率提升 30 倍,写代码必备
Basic concepts of graph theory
【TcaplusDB知识库】批量复制游戏区
【Ubuntu】【Mysql】ubuntu安装了mysql 但是编译报错 mysql.h: No such file or directory
分享 60 个神级 VS Code 插件
Devops note-05: what are the roles of Ba, SM, Po, PM, PD, dev, OPS and QA in the IT industry
MySQL Varcahr to int
Share 60 divine vs Code plug-ins