Home  >  Q&A  >  body text

Mysql多表查询问题

场景:
系统每天会生成一个mysql数据表,里面存储的当天的模块访问量,假设字段为pv。如何统计一个月的模块访问量呢?每个表的结构都是一样的。

非常感谢!

大家讲道理大家讲道理2742 days ago1961

reply all(12)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:04:42

    1. If the amount of data per day is not particularly large, you can divide the tables by month, so that the problem only needs to be queried and counted in one table;
    2. Use views to create multi-table views, but if the amount of data is large, it will take a long time.
    3. In the case of large amounts of data, relational databases are not a good choice just for recording statistics. You can consider NoSQL, such as Hbase.

    reply
    0
  • 高洛峰

    高洛峰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? ? ?

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:04:42

    Try creating a view with multiple tables

    reply
    0
  • 迷茫

    迷茫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.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:04:42

    Create a data table every day? Are you crazy

    reply
    0
  • 天蓬老师

    天蓬老师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

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:04:42

    This expression is also earth-shattering

    reply
    0
  • PHPz

    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.

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:04:42

    Brother, was this built under the guidance of sub-table thinking?

    reply
    0
  • PHP中文网

    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.

    reply
    0
  • Cancelreply