##甲克鱼	1000363	   积分	10元话费*1	DELETE FROM user_gift WHERE user_gift.id=3079 AND user_gift.u_id=1000363;DELETE FROM user_exchange_info WHERE user_exchange_info.id=63 AND user_exchange_info.u_id=1000363;UPDATE user_fund SET VipPoints=VipPoints+110000 WHERE FbId=1000363;UPDATE rooms set `Status`=1 where RoomName like '%8%';  #开启机器人相关房间##查询碎片个数select * from user_prize_log where uid = (select fbid from users where FbName = '小豆2323337173') and prizeId in (22,23);##查询积分情况select sum(vippoints)/10000 from user_fund where fbid<10000000;##查询每日签到存在多条记录select * from signin as s right join (select u_id,sign_date from signin where sign_date>='2015-06-01' group by u_id, sign_date  having count(*) > 1) as aa on aa.u_id = s.u_id and aa.sign_date = s.sign_date;##删除一段时间数据DELETE from game_action WHERE ActionTime<"2015-08-01 00:00:00";##比赛场名次查询SELECT fbid,fbname from users where fbid in (SELECT fbid from match_users where matchid=1508 ORDER BY FbId DESC);SELECT * from match_users where matchid=1508;SELECT * from matchs where MatchStopTime="2015-09-19 14:00:00" and MatchConfigId=3;##商品合成IDUPDATE goods_compound_log gcl, goods_compound gc SET gcl.g_id = gc.g_id WHERE gcl.f_id = gc.f_id;##批量更新筹码UPDATE user_fund set chips=chips+90000 WHERE u_id in (1019133,1056848,1053731,1036275,1015810,1055824,1054226,1003362);##增加vip等级1为3天时间update	user_vip set 	valid_time = if(valid_time < now(), '2015-10-25 19:00:00', date_add(valid_time, interval 3 day)) ,lv=1where u_id in(1000001,1000002,1000003,1000004);##添加公关为1天时间insert into user_gift(g_id, u_id, number, g_type, is_adorn, cre_time, valid_time) values(24557, 1055824, 1, 2, 0, now(), date_add(now(), interval 1 day)); ##添加大喇叭为23天insert into user_gift(g_id, u_id, number, g_type, is_adorn, cre_time, valid_time) values(31121, 1046373, 2500, 3, 0, now(), date_add(now(), interval 23 day)); ##查询昨日赢利牌行榜SELECT	uid,	g.chips AS chips,	uv.lv AS vipLevel,	ui.nickname,	ui.is_robot AS type,	ui.figureurl AS p_w_picpathFROM (	SELECT		fbid AS uid,		SUM(ChangeChips) AS chipsFROM game_userlog force index(ix_gametime)WHERE begintime >= '2015-11-02 04:00:00.0'AND begintime < '2015-11-03 04:00:00.0'GROUP BY fbidORDER BY chips DESCLIMIT 0, 30) g, user_count uc, user_info ui, user_vip uvWHERE g.uid = uc.u_idAND g.uid = ui.u_idAND g.uid = uv.u_idAND g.chips > 0;##到达大厅人数set @startdate='2015-6-18 4:00:00';set @enddate='2015-6-19 4:00:00';select (select count(alu.fbid) from (select fbid,count(fbid) from user_node_log where node=0 and CreateTime>=@startdate and CreateTime<=@enddate group by fbid) as alu) as 所有用户访问人数,(select sum(ucount) from (select fbid,count(fbid) as ucount from user_node_log where node=0 and CreateTime>=@startdate and CreateTime<=@enddate group by fbid) as fwrs) as 所有用户访问次数,(select count(alu.fbid) from (select fbid,count(fbid) from user_node_log where node=9 and CreateTime>=@startdate and CreateTime<=@enddate group by fbid) as alu) as 所有用户到大厅人数,(select sum(alu.count) from (select fbid,count(fbid) as count from user_node_log where node=9 and CreateTime>=@startdate and CreateTime<=@enddate group by fbid) as alu) as 所有用户到大厅次数,(select count(*) from (select unl.fbid,count(unl.fbid) from user_node_log as unl,(select fbid from users where RegTime>=@startdate and RegTime<=@enddate) as un where unl.fbid=un.fbid and unl.node=9 and unl.CreateTime>=@startdate and unl.CreateTime<=@enddate group by unl.fbid) as nunl) as 新用户到大厅人数,(select count(*) from (select  gu.fbid from game_userlog as gu,(select fbid,count(fbid) from user_node_log where node=9 and CreateTime>=@startdate and CreateTime<=@enddate group by fbid) as lu where gu.fbid=lu.fbid and gu.EndTime>=@startdate and gu.EndTime<=@enddate group by gu.fbid) as lwp) as 所有用户到大厅玩牌人数,(select count(*) from (select  gu.fbid from game_userlog as gu,(select unl.fbid,count(unl.fbid) from user_node_log as unl,(select fbid from users where RegTime>=@startdate and RegTime<=@enddate) as un where unl.fbid=un.fbid and unl.node=9 and unl.CreateTime>=@startdate and unl.CreateTime<=@enddategroup by unl.fbid) as lu where gu.fbid=lu.fbid and gu.EndTime>=@startdate and gu.EndTime<=@enddate group by gu.fbid) as lwp) as 新用户到大厅玩牌人数insert into 	goods_price(`type`,`g_id`,`currency_type`,`price`)select 	1 AS type, 	id AS g_id, 	currency_type, 	pricefrom goods where currency_type in(1,3,4)order by g_id;
#取出保险箱筹码update 	user_fund uf, 	safe sset 	uf.chips = uf.chips + s.amount,	s.amount = 0where   uf.u_id = s.u_id	and uf.u_id not in	( 		select distinct u_id from (   #####去除重复的记录			select u_id from deposit			union all 			select u_id from tcpay_log		) aa	) 	and uf.u_id not in(1008728, 1064569, 1064491, 1056812); 	#查询保险箱筹码select ui.u_id, ui.nickname, s.amount from safe s, user_info ui where ui.u_id = s.u_id and amount > 0;
# 修改用户账户筹码update 	user_fund uf, 	user_info ui set 	chips =    case	when ui.last_login_time < '2015-06-16' and chips > 3000	then 3000	when ui.last_login_time < '2015-11-16' and chips > 10000		then 10000	when ui.last_login_time > '2015-11-16' and chips > 50000		then 50000	else chips   end	where   uf.u_id = ui.u_id	and uf.u_id not in	( 		select distinct u_id from (			select u_id from deposit			union all 			select u_id from tcpay_log		) aa	) 	and ui.is_robot = 0	and uf.u_id not in(1008728, 1064569, 1064491, 1056812); 	# 查询玩家筹码:select ui.u_id, ui.nickname, uf.chips from user_fund uf, user_info ui where uf.u_id = ui.u_id and uf.u_id<20000000000000 ORDER BY uf.chips desc;
CREATE TABLE `plotline` (                                                                            `id` int(11) NOT NULL COMMENT '主线任务id',                                              `title` varchar(50) NOT NULL COMMENT '任务标题',                                         `content` varchar(150) NOT NULL COMMENT '内容',                                          `n_id` int(11) NOT NULL COMMENT '下一个任务id',                                          `type` int(11) NOT NULL COMMENT '任务类型',                                              `state` tinyint(2) NOT NULL COMMENT '状态 0取消 1使用',                                  `criterion` int(11) NOT NULL COMMENT '条件',                                             `prize_type` tinyint(4) NOT NULL COMMENT '奖品类型 0没有 1货币 2商品 3礼包 4抽奖次数',              `prize_id` int(11) NOT NULL COMMENT '奖品id',                                            `prize_num` int(11) NOT NULL COMMENT '奖品数量',                                         PRIMARY KEY (`id`)                                                                     ) ENGINE=InnoDB DEFAULT CHARSET=utf8;          insert into `plotline` (`id`, `title`, `content`, `n_id`, `type`, `state`, `criterion`, `prize_type`, `prize_id`, `prize_num`) values('1','“盲注5/10”玩牌一次','参加一次牌局(加入QQ群:237101389暗号:福利,找客服就能换话费哦)。','2','1014','1','1','3','53','1');insert into `plotline` (`id`, `title`, `content`, `n_id`, `type`, `state`, `criterion`, `prize_type`, `prize_id`, `prize_num`) values('2','跟注一次','当您觉得牌型不错的时候,不妨点击一次“跟注”看看。','3','1111','1','1','1','3','400');insert into `plotline` (`id`, `title`, `content`, `n_id`, `type`, `state`, `criterion`, `prize_type`, `prize_id`, `prize_num`) values('3','弃牌一次','当您觉得牌型落后的时候,可以点击“弃牌”放弃哦。','4','1112','1','1','1','3','400');
CREATE TABLE `entry_group` (  `entry` varchar(255) NOT NULL,  `gid` tinyint(4) NOT NULL,  `name` varchar(255) DEFAULT NULL,  `info` varchar(255) DEFAULT NULL,  KEY `index_entry` (`entry`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;INSERT INTO `entry_group` VALUES ('web_qq', '1', 'qq空间', 'qq空间');INSERT INTO `entry_group` VALUES ('web_joker', '2', '官网', '官网');INSERT INTO `entry_group` VALUES ('mobile_qq', '3', '应用宝', '应用宝qq');INSERT INTO `entry_group` VALUES ('mobile_wx', '3', '应用宝', '应用宝微信');ALTER TABLE `user_info` ADD COLUMN `egid` TINYINT DEFAULT 0 NULL AFTER `entry`;UPDATE user_info u INNER JOIN entry_group e ON u.entry = e.entry SET u.egid = e.gid ;BEGIN	SET @pf = new.entry;	SET @aa = (SELECT gid FROM entry_group WHERE entry = @pf);	SET new.egid = @aa;END
活跃在线数据统计select sum(sec0) as "活跃在线总人数",sum(sec1) as "活跃时长〉5时长〈=15",sum(sec2) as "活跃时长〉15时长〈=60",sum(sec3) as "活跃时长〉60时长〈=180",sum(sec4) as "活跃时长〉180时长〈=480",sum(sec5) as "活跃时长〉480"FROM (select CASE WHEN sec>15*60THEN 1ELSE0END as sec0,CASE WHEN sec>5*60 and sec<=15*60THEN 1ELSE0END as sec1,CASE WHEN sec>15*60 and sec<=60*60THEN 1ELSE0END as sec2,CASE WHEN sec>60*60 and sec<=180*60THEN 1ELSE0END as sec3,CASE WHEN sec>180*60 and sec<=480*60THEN 1ELSE0END as sec4,CASE WHEN sec>480*60THEN 1ELSE0END as sec5 from (select sum(UNIX_TIMESTAMP(t.EndTime)-UNIX_TIMESTAMP(t.BeginTime)) as sec from (select distinct gu.FbId, gu.BeginTime, gu.EndTimefrom game_userlog gu, users uwhere gu.FbId = u.FbId and u.IsRobot=0 and gu.BeginTime >= '2015-06-07 04:00:00' and gu.EndTime < '2015-06-08 04:00:00') tGROUP BY t.FbId)tt)ttt;
DELIMITER $$DROP PROCEDURE IF EXISTS `qqtexas`.`p_user_chips_log`$$CREATE DEFINER=`develop`@`%` PROCEDURE `p_user_chips_log`()BEGIN	TRUNCATE TABLE p_user_chips;	INSERT INTO 		p_user_chips(u_id, chips, cre_time) 	SELECT 		u_id, 		SUM(chips) as chips,		now() AS cre_time	FROM (		SELECT			u_id,			chips		FROM user_fund		UNION ALL		SELECT			u_id,			amount AS chips		FROM safe			) aa	GROUP BY u_id;END
BEGIN  DECLARE n_minid BIGINT;  DECLARE n_maxid BIGINT;  DECLARE n_rows BIGINT DEFAULT 1000;   DECLARE n_sleep INT DEFAULT 0;    DECLARE n_day INT DEFAULT 7;      SET autocommit=0;    SELECT id INTO n_minid FROM game_action ORDER BY id LIMIT 1;    SELECT MAX(id) INTO n_maxid FROM game_action WHERE RoundID = (    SELECT RoundID FROM game_log WHERE BeginTime
<= n_maxid - n_rows DO    DELETE FROM game_action WHERE id BETWEEN n_minid AND n_minid + n_rows;    COMMIT;        IF n_sleep > 0 THEN      SELECT SLEEP(n_sleep);    END IF;        SET n_minid = n_minid + n_rows;  END WHILE;    SELECT id INTO n_minid FROM match_gameaction ORDER BY id LIMIT 1;    SELECT MAX(id) INTO n_maxid FROM match_gameaction WHERE RoundID = (    SELECT RoundID FROM match_gamelog WHERE BeginTime
<= n_maxid - n_rows DO    DELETE FROM match_gameaction WHERE id BETWEEN n_minid AND n_minid + n_rows;    COMMIT;        IF n_sleep > 0 THEN      SELECT SLEEP(n_sleep);    END IF;            SET n_minid = n_minid + n_rows;  END WHILE;    SELECT RoundID INTO n_minid FROM gen_roundid ORDER BY RoundID LIMIT 1;  SELECT RoundID-1000 INTO n_maxid FROM gen_roundid ORDER BY RoundID DESC LIMIT 1;    WHILE n_minid <= n_maxid - n_rows DO    DELETE FROM gen_roundid WHERE RoundID BETWEEN n_minid AND n_minid + n_rows;    COMMIT;        IF n_sleep > 0 THEN      SELECT SLEEP(n_sleep);    END IF;            SET n_minid = n_minid + n_rows;  END WHILE;      SELECT RoundID INTO n_minid FROM match_roundid ORDER BY RoundID LIMIT 1;  SELECT RoundID-1000 INTO n_maxid FROM match_roundid ORDER BY RoundID DESC LIMIT 1;    WHILE n_minid <= n_maxid - n_rows DO    DELETE FROM match_roundid WHERE RoundID BETWEEN n_minid AND n_minid + n_rows;    COMMIT;        IF n_sleep > 0 THEN      SELECT SLEEP(n_sleep);    END IF;            SET n_minid = n_minid + n_rows;  END WHILE;        SET autocommit=1;  END
BEGIN	DECLARE r_id INT;	DECLARE r_fbid BIGINT;	DECLARE r_toid BIGINT;	DECLARE r_type TINYINT;	DECLARE r_time TIMESTAMP;	DECLARE r_isfriend INT;	DECLARE b INT DEFAULT 0;	DECLARE r_ids CURSOR FOR SELECT Id FROM user_relation WHERE RelationType != 0 AND RelationFlag = 0 AND fbid < 1111111111111; 	DECLARE CONTINUE HANDLER FOR NOT FOUND SET b = 1;	OPEN r_ids;		REPEAT		FETCH r_ids INTO r_id;				SELECT Fbid,ObjectFbId,RelationType,CreateTime INTO r_fbid,r_toid,r_type,r_time FROM user_relation WHERE Id = r_id;				#是否是好友 0不是 1是		SELECT SUM(c) INTO r_isfriend		FROM		(			SELECT COUNT(*) AS c FROM user_friends WHERE u_id = r_fbid AND friend_id = r_toid			UNION ALL			SELECT COUNT(*) AS c FROM user_friends WHERE u_id = r_toid AND friend_id = r_fbid		) aa;				IF r_isfriend <= 0 THEN		        INSERT INTO user_friends(u_id, friend_id, type, cre_time) VALUES (r_fbid, r_toid, r_type, r_time); 				END IF;	UNTIL b = 1	END REPEAT;		CLOSE r_ids;    END
BEGIN	    set @starttime = date_sub(date_add(date(now()),interval 4 hour),interval 1 day);    set @endtime = date_add(date(now()),interval 4 hour);    		set @login_cnt = (select count(distinct(fbid)) from user_login_log 	where loginTime >= @starttime     and loginTime < @endtime);        	set @active_cnt = (select count(distinct(fbid)) from game_userlog 	where BeginTime >= @starttime	and BeginTime < @endtime);		set @register_cnt = (select count(fbid) from users 	where regtime >= @starttime	and regtime < @endtime);		set @logonday2 = (select count(distinct(fbid)) from user_login_log a	where logintime < date_add(     date_add(date((select RegTime as regtime from users where fbid= a.fbid)),interval 4 hour)	 ,interval 1 day	));		set @logonday3 = (select count(distinct(fbid)) from user_login_log a	where logintime >= date_add(     date_add(date((select RegTime as regtime from users where fbid= a.fbid)),interval 4 hour)     ,interval 1 day	)	and logintime < date_add(     date_add(date((select RegTime as regtime from users where fbid= a.fbid)),interval 4 hour)     ,interval 2 day   ));		set @logonday7 = (select count(distinct(fbid)) from user_login_log a	where logintime >= date_add(     date_add(date((select RegTime as regtime from users where fbid= a.fbid)),interval 4 hour)     ,interval 5 day	)	and logintime < date_add(     date_add(date((select RegTime as regtime from users where fbid= a.fbid)),interval 4 hour)     ,interval 6 day   ));		set @sumchips = (select sum(chips) from user_fund);		set @r_sumchips = (select sum(chips) from user_fund where fbid in (select fbid from users where IsRobot=1));		set @totalcharge = (select sum(amt) from deposit 	where upd_time >= @starttime	and upd_time < @endtime);		set @num_times = (select concat(CAST(count(distinct(u_id)) as char)," / ",cast(count(u_id) as char)) from deposit	where upd_time >= @starttime	and upd_time < @endtime);        		set @sign_num = (select count(distinct(u_id)) from signin 	where sign_date >= @starttime	and sign_date < @endtime);		set @award8 = (select count(distinct(u_id)) from activity_award_log 	where award_id=8 	and cre_time >= @starttime	and cre_time < @endtime);		set @activ4 = (select concat(CAST(count(distinct(u_id)) as char)," / ",cast(count(u_id) as char)) from activity_award_log	where activ_id=4	and cre_time >= @starttime	and cre_time < @endtime);		set @award10 = (select count(distinct(u_id)) from activity_award_log 	where award_id=10	and cre_time >= @starttime	and cre_time < @endtime);		set @award11 = (select count(distinct(u_id)) from activity_award_log 	where award_id=11	and cre_time >= @starttime	and cre_time < @endtime);		set @award12 = (select count(distinct(u_id)) from activity_award_log 	where award_id=12	and cre_time >= @starttime	and cre_time < @endtime);		set @award13 = (select count(distinct(u_id)) from activity_award_log 	where award_id=13	and cre_time >= @starttime	and cre_time < @endtime);		set @award14 = (select count(distinct(u_id)) from activity_award_log 	where award_id=14	and cre_time >= @starttime	and cre_time < @endtime);		set @award15 = (select count(distinct(u_id)) from activity_award_log 	where award_id=15	and cre_time >= @starttime	and cre_time < @endtime);		set @award46 = (select count(distinct(u_id)) from activity_award_log 	where award_id=46	and cre_time >= @starttime	and cre_time < @endtime);		set @award47 = (select count(distinct(u_id)) from activity_award_log 	where award_id=47	and cre_time >= @starttime	and cre_time < @endtime);		set @award48 = (select count(distinct(u_id)) from activity_award_log 	where award_id=48	and cre_time >= @starttime	and cre_time < @endtime);		set @award49 = (select count(distinct(u_id)) from activity_award_log 	where award_id=49	and cre_time >= @starttime	and cre_time < @endtime);		set @award50 = (select count(distinct(u_id)) from activity_award_log 	where award_id=50	and cre_time >= @starttime	and cre_time < @endtime);    set @all9k = (SELECT sum(GoldValue) from user_fund);  set @jbp_num_times = "";  SET @allvippoint = (SELECT SUM(VipPoints) FROM user_fund WHERE fbid<1000000000);  SET @robotchippool = (SELECT ConfigValue FROM sys_config WHERE `ConfigKey` = 'robotallchips');  SET @jewelbox = (SELECT ConfigValue FROM `sys_config` WHERE `ConfigKey` = 'jewelboxmoney');  SET @phonepiece = (SELECT SUM(number) FROM user_gift WHERE (g_id = '90001' OR g_id = '90002'));                insert into basic_run_data(create_time,fetch_date,logon_count,active_count,install_count,    logon_twice_count,logon_third_count,logon_week_count,sys_total,robot_total,    charge_sum,charge_count_times, allgold,allvippoint,robotchippool,jewelbox,phonepiece)    values(NOW(),date_format(date_sub(date(now()),interval 1 day), '%Y-%m-%d'),    @login_cnt,@active_cnt,@register_cnt,@logonday2,@logonday3,@logonday7,    @sumchips,@r_sumchips,@totalcharge,@num_times,@all9k,@allvippoint,@robotchippool,@jewelbox,@phonepiece);	    insert into active_run_data(fetch_date,signin_count,first_charge_count,draw_num_times,    five_award_count,ten_award_count,thirty_award_count,sixty_award_count,twoh_award_count,    threeh_award_count,three_fruit_count,ten_fruit_count,twentyfive_fruit_count,    fifty_fruit_count,eighty_fruit_count,jbp_num_times)    values(date_format(date_sub(date(now()),interval 1 day), '%Y-%m-%d'),@sign_num,    @award8,@activ4,@award10,@award11,@award12,@award13,@award14,@award15,@award46,    @award47,@award48,@award49,@award50,@jbp_num_times);    END
ALTER TABLE `game_userlog`ADD INDEX `ix_RoomLevel` (`RoomLevel`, `FbId`, `BeginTime`) USING BTREE ;ALTER TABLE `goods`ADD COLUMN `valid_time`  timestamp NULL COMMENT '有效期 具体哪天' AFTER `valid_time`;ALTER TABLE `users`ADD COLUMN `address`  varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '地址' AFTER `phone`,ADD COLUMN `realName`  varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '真实姓名' AFTER `address`;lter table `qqtexas`.`user_vip_log` add column `type` tinyint NOT NULL COMMENT '类型 1首次赠送 2每日登陆赠送' after `uv_id`;alter table `qqtexas`.`safe_log` add column `to_uid` bigint NOT NULL COMMENT '对方id' after `u_id`,change `s_id` `u_id` bigint(11) NOT NULL comment '用户id';##商城修改user_vip_log表字段 alter table `qqtexas`.`user_vip_log` add column `points` int NOT NULL COMMENT '点数' after `chips`,change `amt` `chips` int(11) NOT NULL comment '领取筹码';alter table `qqtexas`.`user_vip_log` change `uv_id` `uv_id` varchar(50) NOT NULL comment '用户vip id  user_gift表主键';alter table `qqtexas`.`user_goods_log` drop column `u_id`,change `ugoods_id` `user_goods_id` int(11) NOT NULL comment '用户商品id';alter table `qqtexas`.`user_goods_log` drop column `num`, drop column `g_type`, drop column `price`;alter table `qqtexas`.`users` add column `is_get_friends` tinyint(2) DEFAULT '0' NOT NULL COMMENT '是否已经获取过平台好友 0否 1是' after `IsRobot`,change `IsRobot` `IsRobot` tinyint(4) default '0' NOT NULL comment '是否机器人 0否 1是';##修改表名rename table `qqtexas`.`goods_compound_config` to `qqtexas`.`goods_compound`;insert into goods_use_interval(g_id, interval_time) select id as g_id, timeinterval as interval_time from goods where id in(31120, 31121);insert into 	gift_bag(b_id, b_name, img, g_type, g_id, num, send_type, status)values	(9000, '首冲大礼包', 'joker', 1, 3, 60000, 0, 1),	(9000, '首冲大礼包', 'joker', 2, 31121, 4, 0, 1),	(9000, '首冲大礼包', 'joker', 2, 24559, 1, 0, 1),insert into 	goods_price(`type`,`g_id`,`currency_type`,`price`)select 	1 AS type, 	id AS g_id, 	currency_type, 	pricefrom goods where currency_type in(1,3,4)order by g_id;
##修正用户好友数量UPDATE 	user_count uc, 	(		SELECT 			uid, SUM(c) AS friend_count		FROM		(			SELECT u_id  AS uid, COUNT(*) AS c FROM user_friends GROUP BY u_id			UNION ALL			SELECT friend_id AS uid,  COUNT(*) AS c FROM user_friends GROUP BY friend_id		) aa GROUP BY uid	) uf,	(		SELECT u_id AS uid, COUNT(*) invite_count FROM user_invite GROUP BY u_id	) ui,	(		SELECT u_id AS uid, COUNT(*) share_count FROM user_invite GROUP BY u_id	) usSET 	uc.friend_count = uf.friend_count,	uc.invite_count = ui.invite_count,	uc.share_count = us.share_countWHERE  uc.u_id = uf.uid AND uc.u_id = ui.uid AND uc.u_id = us.uid;
##平台修改UPDATE 	user_count uc,	(		SELECT u_id AS uid, COUNT(*) achieve_count FROM user_achieve GROUP BY u_id	) uaSET 	uc.achieve_count = ua.achieve_countWHERE  uc.u_id = ua.uid;
##聚宝盆数据统计select count(distinct t.Fbid) as "聚宝盆投注总人数", count(t.Fbid) as "聚宝盆投注总次数", count(distinct Winner) as "聚宝盆中奖人数", SUM(t.WinnerCou) as "聚宝盆中奖次数", SUM(t.WinMoney) as "聚宝盆中奖总金额", count(t.Fbid) * 1800 - SUM(t.WinMoney) as "聚宝盆盈亏"from (select Fbid, WinMoney, CASE WHEN WinMoney > 0 then 1ELSE 0end as WinnerCou, CASE WHEN WinMoney > 0 then FbidELSE NULLend as Winnerfrom jewel_box where WinTime >= '2015-04-22 04:00:00' and WinTime < '2015-04-23 04:00:00')t;
##瑶瑶乐数据统计select count(distinct t.Fbid) as "摇摇乐投注总人数", count(t.Fbid) as "摇摇乐投注总次数", count(distinct Winner) as "摇摇乐中奖人数", SUM(t.WinnerCou) as "摇摇乐中奖次数", SUM(t.winchips) as "摇摇乐中奖总金额", SUM(t.betchips) - SUM(t.winchips) as "摇摇乐盈亏"from (select Fbid, winchips,betchips, CASE WHEN winchips > 0 then 1ELSE 0end as WinnerCou, CASE WHEN winchips > 0 then FbidELSE NULLend as Winnerfrom betShake_log where bettime >= '2015-05-07 04:00:00' and bettime < '2015-05-08 04:00:00')t;
##用户登录统计select sum(a.count0) as "登录用户", sum(a.count1) as "非零用户", sum(a.count2) as "活跃用户"from (select CASE WHEN t.FbId>0 then 1ELSE 0END as count0, CASE WHEN tt.ExpValue>10 or tt.ExpValue < -10 then 1ELSE 0END as count1,CASE WHEN ttt.sec>15*60THEN 1ELSE0END as count2from users u,(select distinct FbId from user_login_logwhere LoginTime >= '2015-04-27 04:00:00' and LoginTime < '2015-04-28 04:00:00' )tLEFT JOIN (select SUM(exp_value) as ExpValue, u_id from user_exp_logwhere cre_time >= '2015-04-27 04:00:00' and cre_time < '2015-04-28 04:00:00' GROUP BY u_id)tt on t.FbId = tt.u_idLEFT JOIN(select sum(UNIX_TIMESTAMP(temp.EndTime)-UNIX_TIMESTAMP(temp.BeginTime)) as sec, temp.FbId from (select distinct gu.FbId, gu.BeginTime, gu.EndTimefrom game_userlog guwhere gu.BeginTime >= '2015-04-27 04:00:00' and gu.EndTime < '2015-04-28 04:00:00') tempGROUP BY temp.FbId)ttt on t.FbId = ttt.FbIdwhere u.FbId = t.FbId and u.IsRobot=0 ) a;