mysql分表后组合查询
Posted 6min
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql分表后组合查询相关的知识,希望对你有一定的参考价值。
<?php //注册到月份表 $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分表后组合查询的主要内容,如果未能解决你的问题,请参考以下文章