mysql数据库 sql语句实现查询两个日期区间日期的数据报表

SELECT
GROUP_CONCAT( t1.date_str ) AS xdata,
GROUP_CONCAT( COALESCE ( t2.yAxisData, 0 ) ) ydata
FROM
(
SELECT
@cdate := date_add( @cdate, INTERVAL - 1 DAY ) AS date_str
FROM
(
SELECT @cdate := date_add( DATE_FORMAT(#{endDate}, '%Y-%m-%d'), INTERVAL + 1 DAY ) FROM figure_measure_record
) tmp1
WHERE
@cdate > DATE_FORMAT(#{startDate}, '%Y-%m-%d') ORDER BY @cdate asc
) t1
LEFT JOIN
(
SELECT
DATE_FORMAT( m.create_time, '%Y-%m-%d' ) AS date_str,
count( DISTINCT uniquid ) AS yAxisData
FROM
user_tab AS m
WHERE

=  DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%s') ]]>


GROUP BY DATE_FORMAT( m.create_time, '%Y-%m-%d' )

) t2 ON t1.date_str = t2.date_str

mysql数据库 sql语句实现查询两个日期区间日期的数据报表_第1张图片

你可能感兴趣的:(sql语句)