欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mysql case when group by 實例詳解

 更新時間:2018年01月02日 22:26:25   投稿:mdxy-dxy  
這篇文章主要介紹了mysql 中類似php switch case 的語句,需要的朋友可以參考下

mysql 中類似php switch case 的語句。

  1. select xx字段,  
  2.  case 字段
  3.         when 條件1 then 值1  
  4.         when 條件2 then 值2
  5.         else 其他值 END 別名 
  6. from 表名; 

下面是一個分組求和示例:

select sum(redpackmoney) as stota,ischeck 
from t_redpack
group by isCheck 

使用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_redpack
group by isCheck 

checkinfo中 -1, 0, 1 替換為 checkfalse, uncheck, checktrue(CASE WHEN進行字符串替換處理)

以上就是mysql中case when語句的簡單使用示例介紹。

相關(guān)文章

最新評論