<?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); ?>
原文地址:https://www.cnblogs.com/6min/p/11122919.html
时间: 2024-10-25 21:38:15