SELECT b.createDate,IFNULL(aa.pv,0) pv,IFNULL(aa.uv,0) uv from
(SELECT
create_date createDate,
COUNT(1) pv,
COUNT(DISTINCT wechat_user_id) uv
FROM applet_link_click
WHERE type_id = #{typeId}
AND record_type = #{recordType}
and from_id= #{newsId}
AND create_date between date_add(CURDATE(), interval -1 month) and DATE_SUB(CURDATE(),INTERVAL 1 DAY)
GROUP BY create_date
) aa
RIGHT JOIN
(select a.Date as createDate from
(select curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date from
(select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
cross join
(select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
cross join
(select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) a
where a.Date between DATE_SUB(CURDATE(), INTERVAL 30 DAY) and DATE_SUB(CURDATE(),INTERVAL 1 DAY))b ON b.createDate = aa.createDate
GROUP_CONCAT(case when news.id != ' ' THEN news.id else null END) newsIds,
GROUP_CONCAT(case when news.url_number != ' ' THEN news.url_number else null END) newsNumber
FROM
applet_third_resources n
LEFT JOIN applet_third_resources_relation ralation ON n.id = ralation.third_resources_id
LEFT JOIN applet_news news ON ralation.from_id = news.id
WHERE
1 = 1
<iftest="source != null">
AND n.resource_source = #{source}
</if>
<iftest="resourcesType != null">
AND n.resource_type = #{resourcesType}
</if>
GROUP BY
n.id
ORDER BY
n.update_time DESC
)result where 1 = 1
<iftest="keyValue != null">
AND (result.number LIKE CONCAT("%",#{keyValue},"%") or result.name LIKE CONCAT("%",#{keyValue},"%") or result.newsNumber LIKE CONCAT("%",#{keyValue},"%"))
SELECT b.createDate,IFNULL(aa.pv,0) pv,IFNULL(aa.uv,0) uv from
(SELECT
DATE_FORMAT(create_time,'%Y-%m-%d') createDate,
COUNT(1) pv,
COUNT(DISTINCT wechat_user_id) uv
FROM applet_thirdresources_click_record
WHERE 1=1
AND record_type = #{recordType}
and third_resources_id= #{thirdResourcesId}
AND create_time between date_add(CURDATE(), interval -1 month) and DATE_SUB(CURDATE(),INTERVAL -1 DAY)
GROUP BY third_resources_id,DATE_FORMAT(create_time,'%Y-%m-%d')
) aa
RIGHT JOIN
(select a.Date as createDate from
(select curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date from
(select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
cross join
(select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
cross join
(select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) a
where a.Date between DATE_SUB(CURDATE(), INTERVAL 30 DAY) and DATE_SUB(CURDATE(),INTERVAL 1 DAY))b ON b.createDate = aa.createDate