当前位置:网站首页>MySQL case when then function use
MySQL case when then function use
2022-06-12 22:21:00 【Beta Tutu】
One 、 Concept
Function description : Judge the meaning of data display ( similar java if)
grammar :
CASE [col_name] WHEN [value1] THEN [result1]…ELSE [default] END
Two 、 actual combat
Create and data
CREATE TABLE `user` (
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT 'id',
`account` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ' account number ',
`password` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ' password ',
`status` bit(1) NULL DEFAULT NULL COMMENT ' state :1 normal ,0 Ban ',
`create_date` timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT ' Creation time ',
`update_date` timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT ' Update time '
)
INSERT INTO `user` VALUES (1, 'lanys', '123', b'1', '2022-06-10 11:03:34', '2022-06-10 11:03:34');
INSERT INTO `user` VALUES (2, 'Tom', '123', b'1', '2022-06-10 11:03:35', '2022-06-10 11:03:35');
INSERT INTO `user` VALUES (3, 'David', '111', b'0', '2022-06-10 11:03:38', '2022-06-10 11:03:38');
Case a
demand : Display the account information status in the data sheet in Chinese ( state :1 -> normal , 0-> Ban ).
Realization effect :
sentence :
SELECT id,account,PASSWORD,
( CASE STATUS WHEN 1 THEN ' normal ' WHEN 0 THEN ' Ban ' ELSE NULL END ) AS STATUS
FROM `user`
Case 2
demand : Set the table data according to the creation time (create_date) What sort statistics do ( Similar timeline ).
Realization effect :
sentence :
SELECT create_date,
CONCAT_WS(
',',
CONCAT( ' Create account account:', account ),
CONCAT( ' password password:', PASSWORD ),
CONCAT( ' Account status :', CASE STATUS WHEN 1 THEN ' normal ' WHEN 0 THEN ' Ban ' ELSE NULL END )
) AS line_info
FROM `user` ORDER BY create_date
边栏推荐
- Is it safe to open an account in tonghuashun? How to open an account
- What are thread scheduler and timeslicing?
- The programmer dedicated to promoting VIM has left. Father of vim: I will dedicate version 9.0 to him
- 2021 rust survey results released: 9354 questionnaires collected
- Create a virtual thread using loom - David
- MySQL introduction and installation (I)
- China embolic coil market trend report, technical innovation and market forecast
- How to perform disaster recovery and recovery for kubernetes cluster? (22)
- The 2023 campus recruitment officially opened! Oceanbase would like to make an interview with you this spring
- Mr. Sun's version of JDBC (21:34:25, June 12, 2022)
猜你喜欢
【概率论与数理统计】期末复习抱佛脚:公式总结与简单例题(完结)
Mysql concat_ws、concat函数使用
Redis optimization
How to specify your webpage's language so Google Chrome doesn't offer to translate it
Database daily question --- day 10: combine two tables
Configuring Dingding notification of SQL audit platform archery
孙老师版本JDBC(2022年6月12日21:34:25)
[image denoising] image denoising based on trilateral filter with matlab code
leetcodeSQL:574. Elected
Open source background management system suitable for outsourcing projects
随机推荐
Market trend report, technical innovation and market forecast of Chinese stump crusher
IPhone: save Boolean into core data - iphone: save Boolean into core data
Create a virtual thread using loom - David
Ansible roles project case (IV)
JS fighting on...
The interface testing tool apipos3.0 is applicable to process testing and reference parameter variables
MySQL architecture and basic management (II)
Open source background management system suitable for outsourcing projects
Research Report on market supply and demand and strategy of tizanidine industry in China
June training (day 11) - matrix
【LeetCode】33. 搜索旋转排序数组
项目里面的traceID的设计
Palindrome linked list and linked list intersection problem (intersecting with Xinyi people) do you really know?
[probability theory and mathematical statistics] final review: formula summary and simple examples (end)
How to perform disaster recovery and recovery for kubernetes cluster? (22)
JVM foundation - > three ⾊ mark
China embolic coil market trend report, technical innovation and market forecast
Unity commonly used 3D mathematical calculation
[C language] data type occupation
My struggle: my years in foreign enterprises (1)