我查询两个表并返回一段时间之间存在的日期。
(
SELECT DATE_FORMAT(date, '%Y-%m-%d') AS date
FROM `users exercises`
WHERE `userid` = $user->id AND (date >= '$begin' AND date <= '$end')
GROUP BY day(date)
ORDER BY date
) UNION ALL (
SELECT DATE_FORMAT(date, '%Y-%m-%d') AS date
FROM `users foods`
WHERE `userid` = $user->id AND (date >= '$begin' AND date <= '$end')
GROUP BY day(date)
ORDER BY date
)
我目前正在使用UNION
,但我觉得可能有更好的方法可以达到我想要的效果吗?
两个表都具有相同的结构:
id | userid | date (timestamp)