mysql订单表中一个字段对应多个优惠卷id,用','隔开。html
财务须要优惠卷使用状况mysql
刚开始用优惠卷id(长度固定,不会出现特殊状况) like 订单表关联id字段 查询,使用'||'拼接'%'。 sql
发现不管是在优惠卷id或订单管理字段加'%'都不能打到要求,最后使用find_in_set()方法 成功实现。spa
代码以下:code
select cou.cp_id as '优惠卷id'htm
,cou.cp_no as '卷号'get
,cast(case cou.generate_type when 0 then '生成' when 1 then '发放' else cou.generate_type string
end AS char(20)) as '生成类型'it
,cast(case cou.state when 0 then '待领用' when 1 then '未使用' when 2 then '已使用' when 3 then '已过时' when 4 then '已失效' else cou.state end as char(20)) as '状态'io
,cast(case cou.is_gift when 0 then '否' when 1 then '是' else '' end as char(20))as '是否礼包领取'
,cast(case cou.cp_type when 1 then '现金券' when 2 then '折扣券' when 3 t