ds1数据集,这个用来单元格展示数据的
select
t.*
from (
SELECT
sd.email,
consume_phone phone,
case hg.group_card_kind when '1' then '赠洗卡' else '现金卡' end as card_type,
CASE WHEN hg.group_card_type IN ('X', 'Y', 'V', 'T') THEN '门市充值'
ELSE '团单'END as card_source,
hg.group_name as group_name,
'消费' operatype,
COUNT(hs.consume_card_kind ) AS times,
IFNULL(sum(IF(hs.consume_status='+',(hs.consume_amount),-(hs.consume_amount))),0) money,
sum(hs.consume_gift_amount) as gift_money,
(IFNULL(sum(IF(hs.consume_status='+',(hs.consume_amount),-(hs.consume_amount))),0)-sum(hs.consume_gift_amount)) as last_money
FROM
qianxun_wash_consume hs
LEFT JOIN qianxun_wash_groupcard hg ON (hs.consume_phone = hg.group_phone and hs.consume_card_kind=hg.group_card_kind)
LEFT JOIN sys_dept sd on sd.dept_id=hg.create_dept
WHERE
consume_subtract_card != '0'
and hs.consume_card_type IS NOT NULL
and hs.create_unit='101'
and hs.consume_card_type <> ' '
AND hs.consume_type IN
( '200', '220' )
${if(len(startdate)>0," and DATE_FORMAT(hs.create_time, '%Y-%m-%d') >='"+startdate+"'","")}
${if(len(enddate)>0," and DATE_FORMAT(hs.create_time, '%Y-%m-%d') ='"+times+"'","")}
) t
where 1=1
${if(len(card_source)=0,"","and t.card_source='"+card_source+"'")}
ORDER BY t.times DESC

ds2数据集2 或者自定义数据字典用来筛选card_source
只返回 门市充值 与 团单 两个值就行了!!!

