1,简单的使用UNION ALL链接连个月表查询
SELECT * FROM user WHERE id = 12
UNION ALL
SELECT * FROM user WHERE id = 12
2,PHP查询用
$StartDate_C = date("Ym", $lastStatime); // 开始日期
$cmtEndDate = date("Ym", $dayEndStatime); // 结束日期
$cmt_sql_BC = "select t1.user_id,t1.type,SUM(t1.jf) as cmt_table_jifen_BRZC from (";
while (strtotime($StartDate_C) <= strtotime($cmtEndDate)) {
$table = "fm_jifen_log.user_jifen_log_" . $StartDate_C;
$cmt_sql_BC .= "SELECT SUM(jifen) AS jf,user_id,type FROM {$table} WHERE type = 44 AND user_id IN (23095,48424,48980,1472,1464,1448,1497)
if (strtotime($StartDate_C) != strtotime($cmtEndDate)) {
$cmt_sql_BC .= " UNION ALL ";
}
$StartDate_C = date("Ym", strtotime("+1 month", strtotime($StartDate_C . '01')));
}
$cmt_sql_BC .= " ) as t1";
$cmt_res_BC = $mysql->getAll($cmt_sql_BC);