带有user_id=的条件,如果user_id有索引,效率应该不会很低
如果没有这个条件其结果似乎没意义了
sql是否如下:
select count(*),user_id, to_char(ub.CREATE_TIME, 'yyyy-MM') as pubTime
from USER_BLOG ub
group by to_char(ub.CREATE_TIME, 'yyyy-MM'),user_id
对于这样的业务,应该将上面的结果生成表如:
select count(*),user_id, to_char(ub.CREATE_TIME, 'yyyy-MM') as pubTime
from USER_BLOG ub
where create_time > '当前月'
group by to_char(ub.CREATE_TIME, 'yyyy-MM'),user_id
每月月末统计上月的结果插入
而后统计工作就变成了只统计当前月,create_time的索引将过滤掉大部分数据
|