Home  >  Q&A  >  body text

mysql分表之后怎么查询

表结构包含id,week,hot,按周切成7张表,每张表代表一周的第几天,week代表第几周,怎么查询第n周hot排名前十的记录?

迷茫迷茫2743 days ago778

reply all(5)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 14:51:20

    The way to divide tables is to avoid cross-table operations. Let business operations be completed in a table.
    If you want to cross tables, it means that the division method is unreasonable.

    If there are really some business scenarios that need to span tables, consider multiple partitioning methods to exist at the same time to create copy redundancy.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:51:20

    Locate the specific table based on the week. To put it bluntly, it means specifying the specific table when generating the sql statement. It has nothing to do with mysql.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:51:20

    The problem of splicing sql statements, table naming should be regular, get the current week, splice, the first 10 hots are completed with order by and top 10 or limit 0,10 keywords

    reply
    0
  • PHPz

    PHPz2017-04-17 14:51:20

    I personally don’t like to put logic into mysql, so according to your table splitting method, you can only take out the top 10 of each table from the seven tables, and then compare them in the application. In addition, I suggest that you divide the table according to the monthly level, so as to support more business needs. Your table partitioning method is more like modular table partitioning, and naturally does not support querying and sorting within a time period.

    reply
    0
  • 黄舟

    黄舟2017-04-17 14:51:20

    This kind of sub-table can only take the top 10 of each table, and then sort it in the code. There is a problem with this sub-table rule. If there is such a scenario, data redundancy needs to be done

    reply
    0
  • Cancelreply