问题描述
--一个业务的所有功能CREATETABLE`buse`(`id`int(11)NOTNULLauto_increment,`name`varchar(255)defaultNULL,`desc`varchar(255)defaultNULL,PRIMARYKEY(`id`))ENGINE=InnoDBDEFAULTCHARSET=latin1;--用户表CREATETABLE`user`(`id`int(11)NOTNULLauto_increment,`username`varchar(255)defaultNULL,`tel`varchar(255)defaultNULL,PRIMARYKEY(`id`))ENGINE=InnoDBDEFAULTCHARSET=latin1;--用户使用功能的历史记录表CREATETABLE`user_buse`(`id`int(11)NOTNULLauto_increment,`user_id`int(11)defaultNULL,`buse_id`int(11)defaultNULL,`date`datetimedefaultNULL,PRIMARYKEY(`id`))ENGINE=InnoDBDEFAULTCHARSET=latin1;--向功能表插入数据INSERTINTO`buse`VALUES('1','b1','x1');INSERTINTO`buse`VALUES('2','b2','x2');INSERTINTO`buse`VALUES('3','b3','x3');INSERTINTO`buse`VALUES('4','b4','x4');--向用户表插入数据INSERTINTO`user`VALUES('1','aaa','1111');INSERTINTO`user`VALUES('2','bbb','222');INSERTINTO`user`VALUES('3','ccc','333');INSERTINTO`user`VALUES('4','ddd','444');--向用户使用功能历史表插入数据INSERTINTO`user_buse`VALUES('1','1','1','2012-08-0311:35:43');INSERTINTO`user_buse`VALUES('2','1','2','2012-08-0111:36:00');INSERTINTO`user_buse`VALUES('3','2','3','2012-08-0311:36:41');INSERTINTO`user_buse`VALUES('4','3','4','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('5','4','4','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('6','1','2','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('7','3','3','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('8','1','4','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('9','3','1','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('10','3','2','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('11','4','1','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('12','4','2','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('13','3','4','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('14','3','1','2012-08-0111:37:00');INSERTINTO`user_buse`VALUES('15','1','4','2012-08-0111:37:00');--业务统计某段时间内使用各项功能一次,二次,三次以上的用户数量占总用户的百分比。统计出来的效果为:--------------------------------------------------------------------------------------------使用次数功能1所占百分比%功能2所占百分比%功能3所占百分比%功能4所占百分比%---------------------------------------------------------------------------------------------1次100.1%100.1%100.1%100.1%---------------------------------------------------------------------------------------------二次100.1%100.1%100.1%100.1%---------------------------------------------------------------------------------------------三次以上100.1%100.1%100.1%100.1%---------------------------------------------------------------------------------------------本人愚昧:以上的sql的非常难写,我也问了一些人。有说写不出来。有的讲业务不对。有的讲业务没有意义。希望大家给我建议。跪求sql希望各位好汉帮帮忙,看下能不能想到,不管oracle或者Mysql。sqlserver本人不知道用。我QQ:297907562----------------------------------------------------------------------------------------------------------