简体   繁体   English

SQL - 如何计算论坛的页数

[英]SQL - How forum number of pages are calculated

I am working on a similar function that forum had, the number of pages in each forum section. 我正在研究论坛所具有的类似功能,每个论坛部分的页数。

My thought and functions as follow: 我的思想和功能如下:

  • A forum may have one or more than one section (sub-forum) 论坛可能有一个或多个部分(子论坛)
  • Each section may have zero or more than one thread 每个部分可以有零个或多个线程
  • Each thread have an unique ID generated by Database (1,2,3...) 每个线程都有一个由Database(1,2,3 ...)生成的唯一ID
  • Each page may only display 15 threads 每个页面可能只显示15个线程
  • A section may have one or more than one pages. 一个部分可能有一个或多个页面。
  • Each thread may have one or more than one pages. 每个线程可以有一个或多个页面。

I have completed all the things except the last two things mentioned above. 除了上面提到的最后两件事,我已经完成了所有的事情。 however, the number of pages has been a problem to me. 但是,页数对我来说是一个问题。 Here's my thought: 这是我的想法:

  • Using Count(key) will definitely do the work, however , I am worried about the performance once the section has lots of threads. 使用Count(key)肯定会完成工作,但是,一旦该部分有很多线程,我担心性能。
  • Finding the last ID and divide it by 15 works too, however it will be inaccurate very soon. 找到最后一个ID并将它除以15也有效,但很快就会出现不准确的情况。

Is there any possible solution to implement this function? 有没有可能的解决方案来实现这个功能? Or is COUNT(key) is the best approach? 或COUNT(关键)是最好的方法?

You could add a column to your thread table (something like 'postCount'), and then increment it whenever a post is added to that thread. 您可以在线程表中添加一个列(类似'postCount'),然后每当帖子添加到该线程时递增它。 Then you could use that value to determine the number of pages instead of counting the number of posts each time. 然后,您可以使用该值来确定页数,而不是每次计算帖子数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM