Chinaunix首页 | 论坛 | 博客
  • 博客访问: 629647
  • 博文数量: 149
  • 博客积分: 3901
  • 博客等级: 中校
  • 技术积分: 1558
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-16 14:33
文章分类

全部博文(149)

文章存档

2014年(2)

2013年(10)

2012年(32)

2011年(21)

2010年(84)

分类: Mysql/postgreSQL

2010-10-21 19:12:47


为解决用户的同属性 大量操作存储问题 :

数据库表结果: 
  用户 |  属性域+  |  当前时间 | 最小时间力度 | int  | int .....

比如 :
  用户1 | 频道1 | ....   | 2010-10-01 | 1天   | 0 
  .....

表结构为 ( 预订表存储 一个月 2010-10 ) :
create table test ( 
   uid int primary key , 
   domain varchar(20),
   starttime datetime,
   endtime  datetime,
   touch int ,
   unique(uid,domain,starttime ) );


用户分别在 10-05 ,10-13  ,10-20 天来过
#10-05 减去 10-01  为 5 天 
insert into test values 
  (1,'yy-xx','2010-10-01','2010-10-05',1<
on duplicate key 
   update endtime = '2010-10-05'  ,  
          touch = ( 1<

# 10-13 减去 10-01  为 13天 
insert into test values 
  (1,'yy-xx','2010-10-01','2010-10-13',1<
on duplicate key 
   update endtime = '2010-10-13'  ,  
          touch = ( 1<

# 10-20 减去 10-01  为 20 天 
insert into test values 
  (1,'yy-xx','2010-10-01','2010-10-20',1<
on duplicate key 
   update endtime = '2010-10-20'  ,  
          touch = ( 1<

当前月 来的 总天数  :
>  select BIT_COUNT(touch) from test ;


上周来天数 (2010-10-03 到 2010-10-09) :
>  select 
  bit_count( 
   ( touch >> datediff('2010-10-03',starttime) ) &
   (1<
  )
from test ;


还有 许多这样的想法 , 后面再说吧 下班 ~ 





阅读(964) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-10-22 11:03:02

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com