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

Detailed explanation of mysql case when group by examples

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

A php switch case-like statement in mysql.

Select xx field, case field when condition 1 then value 1when condition 2 then value 2else other values END alias from table name

The following is an example of grouping summation:

Select sum (redpackmoney) as stota,ischeck from t_redpackgroup by isCheck

Use case when:

Select sum (redpackmoney) as stota, (CASE isCheck WHEN'1' THEN 'checktrue' WHEN' 0' THEN 'uncheck' WHEN'-1' THEN 'checkfalse' ELSE' unknow' END) as checkinfo from t_redpackgroup by isCheck

Replace-1,0,1 in checkinfo with checkfalse, uncheck, checktrue (CASE WHEN performs string replacement processing)

The above is a simple example of the use of case when statements in mysql.

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

Wechat

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

12
Report