mysql分表后组合查询
                        
                            时间:2021-07-01 10:21:17
                            帮助过:33人阅读
							                        
                     
                    
                    
                    //注册到月份表
$sql = "INSERT INTO tbl_view_".
date(‘Ym‘)."(ip,city,dateline) VALUES(‘127.0.0.1‘,‘CHINA‘,1562065253)"
;
$id  = DB::query(
$sql);
//查询的时候按时间条件组合查询SQL
$start_date  = 
strtotime(‘2019-01-01 00:00:00‘
);
$end_date    = 
strtotime(‘2019-07-01 23:59:59‘
);
$month_begin = 
date(‘Ym‘, 
$start_date);
$month_end   = 
date(‘Ym‘, 
$end_date);
$month_plus  = 1
;
$month_next  = 
date(‘Ym‘, 
strtotime("+{
$month_plus} months", 
$start_date));
$UNION_SQL   = "SELECT ip,city,dateline FROM tbl_view_{
$month_begin}"
;
while(
intval(
$month_next) <= 
intval(
$month_end)){
    $UNION_SQL .= " UNION ALL SELECT ip,city,dateline FROM tbl_view_{
$month_next}"
;
    $month_plus += 1
;
    $month_next  = 
date(‘Ym‘, 
strtotime("+{
$month_plus} months", 
$start_date));
}
$sql = "SELECT * FROM (
$UNION_SQL) t WHERE 1 AND dateline BETWEEN 
$start_date AND 
$end_date"
;
$dt  = DB::query(
$sql);
?>
 
mysql分表后组合查询
标签:art   查询   组合查询   tar   next   int   pre   组合   span