Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of the use of case when in MySQL

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report