<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yunzhi.marketing.mapper.TaPersonFromRecordMapper">

    <select id="getNowDataList" resultType="com.yunzhi.marketing.statistic.entity.TsPersonFromStatistic">
        SELECT
            count( 1 ) AS from_num,
            t.scene_type,
            t.event_type,
            t.org_id,
            t.create_date,
            sum( IF ( p.phone IS NOT NULL OR p.tel IS NOT NULL, 1, 0 ) ) AS registered_num
        FROM
            ta_person_from_record t
            LEFT JOIN ta_person p ON t.person_id = p.person_id
        WHERE
            t.is_first_time = 1
            AND DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ), '%Y-%m-%d' )
        GROUP BY
            t.scene_type,
            t.event_type,
            t.org_id
    </select>
</mapper>
