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

Cloud computing learning roadmap materials, courseware, CASE WHEN grammar in msyql

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

In this article, we will explain the syntax of CASE WHEN in msyql:

The case when statement in MySQL that evaluates the list of conditions and returns one of several possible expressions.

CASE has two formats: the simple CASE function compares an expression with a set of simple expressions to determine the result. The CASE search function evaluates a set of Boolean expressions to determine the results. Both support the optional ELSE function.

1) the syntax of a simple CASE function is as follows:

CASE input_expression

WHEN when_expression THEN

Result_expression [... n] [

ELSE

Else_result_expression

END

Parameter introduction

Input_expression is an expression that is evaluated when using a simple CASE format. Input_expression is any valid Microsoft SQL Server expression.

The simple expression compared by input_expression when WHEN when_expression uses the simple CASE format. When_expression is an arbitrarily valid SQL Server expression. Input_expression and each when_expression must have the same data type, or an implicit conversion.

Placeholder, indicating that multiple WHEN when_expression THEN result_expression clauses or WHEN Boolean_expression THEN result_expression clauses can be used.

THEN result_expression the expression returned when input_expression = when_expression is TRUE, or Boolean_expression is TRUE.

Result expression is an arbitrarily valid SQL Server expression.

ELSE else_result_expression the expression returned when the value of the comparison operation is not TRUE. If this parameter is omitted and the value of the comparison operation is not TRUE,CASE, the NULL value is returned. Else_result_expression is an arbitrarily valid SQL Server expression. Else_result_expression and all result_expression must have the same data type, or must be implicitly converted.

Simple CASE function: return result value introduction:

Calculates the input_expression, and then calculates the input_expression = when_expression of each WHEN clause in the specified order.

Returns the first result_expression with a value of TRUE (input_expression = when_expression). If there is no input_expression = when_expression with the value TRUE, SQL Server will return else_result_expression; when the ELSE clause is specified. If no ELSE clause is specified, the NULL value will be returned.

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

Servers

Wechat

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

12
Report