当前位置: 代码迷 >> 综合 >> Mysql语句,用到case when ,concat
  详细解决方案

Mysql语句,用到case when ,concat

热度:71   发布时间:2023-11-01 03:53:02.0
 
 

select s.SHOP_NAME, case when c.COUPON_VALUE = '-1' THEN (concat(c.BEGIN_COUPON_VALUE,'~',c.END_COUPON_VALUE)) ELSE concat(c.COUPON_VALUE) END, case when c.COUPON_CLASS = 'share' then '支付分享券' when c.COUPON_CLASS = 'follow' then '新粉关注券' when c.COUPON_CLASS = 'default' then '商城内部券' end as couponClass, concat(c.COUPON_COUNT), concat(c.SEND_COUNT), case when c.USED_COUNT is null then '0' ELSE concat(c.USED_COUNT) end, concat(c.BEGIN_TIME), concat(c.END_TIME), case when STATUS = 0 then '未停用' when STATUS = 1 THEN '已停用' end, concat(MIN_AMOUNT) FROM shop s INNER JOIN coupon c ON s.SHOP_ID = c.SHOP_ID

 

 

 

 

 

 

 

concat(字段名)将此字段转换成字符串

 

case when 字段名 = ‘值1’ then ‘替换值1’ when 字段名 = ‘值2’  then ‘替换值2’ when 字段名 = ‘值3’ then ‘替换值3’ end

 

case when 字段名 = ‘值1’ then ‘替换值1’ else ‘替换值2’ end

  相关解决方案