场景:
系统每天会生成一个mysql数据表,里面存储的当天的模块访问量,假设字段为pv。如何统计一个月的模块访问量呢?每个表的结构都是一样的。
非常感谢!
PHP中文网2017-04-17 13:04:42
高洛峰2017-04-17 13:04:42
= =
MySQL data tables cannot be built infinitely. What is your design? . .
It is recommended to go home and read a book on database design first. . .
If we put them all in one table from the beginning, it wouldn't be so painful at all, right? ? ?
Have you considered performance and maintainability issues? ? ?
迷茫2017-04-17 13:04:42
select count(1) from pv_150506
union all
select count(1) from pv_150507
union all
........
foreach result set, summed up.
天蓬老师2017-04-17 13:04:42
Let’s assume that he automatically creates tables on a monthly basis, and each table has a lot of data
Search like this
When querying, join the tables and merge the query
Dynamically generate query statements
PHPz2017-04-17 13:04:42
The log record table is designed in such a way that frequent insertions will lock the query operation. In Linux, you can write a shell script to count pv visits.
PHP中文网2017-04-17 13:04:42
Actually, I think depending on the user scenario, if the data in a day is really millions of rows, creating tables in different days is not necessarily a bad decision.