Get the App
SLTechnology News&Howtos  ›  Database  › 

Example Analysis of the use of case when in MySQL

Shulou Source: shulou.com Published: 2022-05-31 22:28:06 10月02日 Update

This article mainly introduces the example analysis of the use of case when in MySQL, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

First, let's create the database table:

CREATE TABLE `tdemo` (`id` int (32) NOT NULL, `name` varchar (255) DEFAULT NULL, `age` int (2) DEFAULT NULL, `num` int (3) DEFAULT NULL, PRIMARY KEY (`id`) ENGINE=InnoDB DEFAULT CHARSET=utf8

Insert data:

INSERT INTO `t _ demo` VALUES ('1Qing,' Zhang San', '21th,' 69')

INSERT INTO `t _ demo` VALUES ('2Qing,' Li Si', '22Qing,' 98')

INSERT INTO `t _ demo` VALUES ('3pm,' Wang Wu', '20pm,' 54')

INSERT INTO `t _ demo` VALUES ('4Qing,' Zhao Tian', '22Qing,' 80')

MySQL case when usage

SELECT *, CASE WHEN t.num > = 85 THEN 'excellent' WHEN t.num

< 90 AND t.num>

= 60 THEN 'General' ELSE 'failed' END AS levelFROM t_demo t

Query structure:

Thank you for reading this article carefully. I hope the article "sample Analysis of the use of case when in MySQL" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles usage methods examples analysis data excellence value interest at the same time database more friends knowledge structure editing industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB Apple macOS OPPO Reno