Mysql语句,用到case when ,concat

来源:互联网 发布:淘宝v任务平台下载 编辑:程序博客网 时间:2024/06/08 17:11

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




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


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


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

原创粉丝点击