我想移除空值并将昨天的值上移但我不知道怎么做.
完整sql:
(SELECT
COUNT(1) toDay, NULL AS yesterDay
FROM
bas_user
WHERE UNIX_TIMESTAMP(user_datetime) BETWEEN UNIX_TIMESTAMP(
DATE_FORMAT(CURDATE(), '%Y-%m-%d %H:%i:%s')
)
AND UNIX_TIMESTAMP(NOW())
GROUP BY HOUR(user_datetime))
UNION
(SELECT
NULL AS toDay,COUNT(1) yesterDay
FROM
bas_user
WHERE UNIX_TIMESTAMP(user_datetime) BETWEEN UNIX_TIMESTAMP(
DATE_SUB(
DATE_FORMAT(CURDATE(), '%Y-%m-%d %H:%i:%s'),
INTERVAL 1 DAY
)
)
AND UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))
GROUP BY HOUR(user_datetime)
)
1条答案
按热度按时间xe55xuns1#
若要合并两个结果集,您需要一个链接索引键。例如,假设
user_id
是两者的链接索引键。结果: