MySQL按月分表,PHP如何做汇总统计查询、排序、分页

WBOY
Release: 2016-06-06 20:33:25
Original
2994 people have browsed it

需求背景

群组表

group

聊天记录表

按月分表,如

chat_message_2015_04

chat_message_2015_05

chat_message_2015_06

表结构

chatTime //message时间
groupID //组ID

需求描述

  1. 给定一个时间段,如当天/最近7天/当月/2015-04-12 ~ 2015-06-17,统计给定时间段内各个group的message数量
  2. 按照统计出来的message数量,对group进行排序与分页输出

回复内容:

需求背景

群组表

group

聊天记录表

按月分表,如

chat_message_2015_04

chat_message_2015_05

chat_message_2015_06

表结构

chatTime //message时间
groupID //组ID

需求描述

  1. 给定一个时间段,如当天/最近7天/当月/2015-04-12 ~ 2015-06-17,统计给定时间段内各个group的message数量
  2. 按照统计出来的message数量,对group进行排序与分页输出

1、UNION
2、若是innodb分表,则可以用merge处理。

直接搞一张专门针对统计数据用的汇总表

如果可能的话,不要采用分表的设计,采用表分区,这样就对于查询就不需要特殊处理了。规划好索引,性能应该不会有问题。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
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!