mysql分表之后怎么查询
迷茫
迷茫 2017-04-17 14:49:20
0
5
780

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

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(5)
Peter_Zhu

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.

小葫芦

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.

小葫芦

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

PHPzhong

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.

黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!