浏览 1576 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-12-26
最后修改:2009-02-27
准备数据: user表 create table users( id int primary key auto_increment, name varchar(25) ); insert into users(name) values ('sunhaojie1'); insert into users(name) values ('sunhaojie2'); insert into users(name) values ('sunhaojie3'); create table events( id int primary key auto_increment, create_date Date, type int, user_id int, foreign key (user_id) references users (id) ); type=1,发送邮件 type=2,接受邮件 insert into events(create_date,type,user_id) values('2007-01-12','1',1); insert into events(create_date,type,user_id) values('2007-01-12','2',2); insert into events(create_date,type,user_id) values('2007-01-12','1',3); insert into events(create_date,type,user_id) values('2007-02-12','1',1); insert into events(create_date,type,user_id) values('2007-02-12','1',1); insert into events(create_date,type,user_id) values('2007-02-12','2',3); insert into events(create_date,type,user_id) values('2007-03-12','1',1); insert into events(create_date,type,user_id) values('2007-03-12','1',1); insert into events(create_date,type,user_id) values('2007-03-12','1',2); insert into events(create_date,type,user_id) values('2007-04-12','1',1); insert into events(create_date,type,user_id) values('2007-04-12','2',1); insert into events(create_date,type,user_id) values('2007-04-12','1',1); insert into events(create_date,type,user_id) values('2007-05-12','1',3); insert into events(create_date,type,user_id) values('2007-05-12','2',1); insert into events(create_date,type,user_id) values('2007-05-12','1',1); insert into events(create_date,type,user_id) values('2007-06-12','1',1); insert into events(create_date,type,user_id) values('2007-06-12','3',3); insert into events(create_date,type,user_id) values('2007-06-12','1',1); insert into events(create_date,type,user_id) values('2007-07-12','1',1); insert into events(create_date,type,user_id) values('2007-07-12','2',1); insert into events(create_date,type,user_id) values('2007-07-12','1',2); insert into events(create_date,type,user_id) values('2007-08-12','1',1); insert into events(create_date,type,user_id) values('2007-08-12','2',2); insert into events(create_date,type,user_id) values('2007-08-12','1',3); insert into events(create_date,type,user_id) values('2007-09-12','1',1); insert into events(create_date,type,user_id) values('2007-09-12','1',1); insert into events(create_date,type,user_id) values('2007-09-12','2',1); insert into events(create_date,type,user_id) values('2007-10-12','1',2); insert into events(create_date,type,user_id) values('2007-10-12','1',1); insert into events(create_date,type,user_id) values('2007-10-12','1',1); insert into events(create_date,type,user_id) values('2007-11-12','1',1); insert into events(create_date,type,user_id) values('2007-11-12','2',3); insert into events(create_date,type,user_id) values('2007-11-12','1',1); insert into events(create_date,type,user_id) values('2007-11-12','1',1); insert into events(create_date,type,user_id) values('2007-12-12','1',1); insert into events(create_date,type,user_id) values('2007-12-12','2',3); insert into events(create_date,type,user_id) values('2007-12-12','2',1); insert into events(create_date,type,user_id) values('2007-12-12','2',1); insert into events(create_date,type,user_id) values('2007-10-12','1',1); insert into events(create_date,type,user_id) values('2007-08-12','1',3); 查询语句: select count(month), month from (select type, date_format(create_date,'%c') month from events where type = 1) as te group by te.month; 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |