select
d.store ,count(*),f.created_date,f.plan_state,g.channel_type
from patrol_plan_result d
left JOIN patrol_plan f on d.patrol_plan=f.id
LEFT JOIN basic_crm_channel g on g.CHANNEL_NBR=f.store
where d.created_date>='2015-05-01' and f.exe_start_time>='2015-05-01'
and f.exe_end_time<='2015-05-31' and f.plan_type=1 and g.is_display=0
and g.STATUS_CD=1000 and g.CHANNEL_CLASS=10
group by d.store having count(*) <=30