$time = time();
$today = strtotime(date('Y-m-d', time()));//零点时间戳
$todayDate = date('Y-m-d', time());
//最近7天
$sevenDaysAgo = strtotime(date('Y-m-d', time())) - 7 * 86400;
$sql = "SELECT
t1.day,
COUNT(t2.id) user_num
FROM
(SELECT
@cdate := DATE_ADD(@cdate, INTERVAL - 1 DAY) day
FROM
(SELECT
@cdate := DATE_ADD('{$todayDate}', INTERVAL + 1 DAY)
FROM
area) t0
LIMIT 7) t1
LEFT JOIN
(SELECT
FROM_UNIXTIME(create_time,'%Y-%m-%d') day,
id
FROM
user_log
WHERE create_time > $sevenDaysAgo
AND create_time < $time
) t2
ON t2.day = t1.day
GROUP BY t1.`day`";
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!