select a.app_id,a.channelname,a.b,count(1) from (SELECT app_id,channelname,device_uuid,count(1) as b FROM `2_mobile_session` WHERE realtime BETWEEN '2011-08-01 00:00:00' and '2011-08-31 23:59:59' and app_id IN ('2x1kfBk63z','Gj9YiT','2S5Wcx','S4zbL7') and channelname IN ('afyl_news1','afyl_news2','afyl_news3','afyl_news4','afyl_news5','dingfeng_news1','dingfeng_news2','dingfeng_news3','dingfeng_news5','dingfeng_news7','dingfeng_news9') GROUP BY app_id,channelname,device_uuid) as a GROUP BY a.app_id,a.channelname,a.b into outfile "/home/mysql/20110916.txt";
计算只使用一次的
SELECT app_id,channelname,device_uuid, count(1) as a FROM `2_mobile_session` WHERE realtime BETWEEN '2011-08-01 00:00:00' and '2011-08-31 23:59:59' and app_id IN ('2x1kfBk63z','Gj9YiT','2S5Wcx','S4zbL7') and channelname IN ('dingfeng_news9','afyl_news4','afyl_news1') GROUP BY app_id,channelname,device_uuid HAVING a =1 into outfile "/home/mysql/20110916_1.txt";
算入安装量的,并且只使用过一次的.
SELECT a.appid,a.channelname,count(1) FROM 2_mobile_device as a INNER JOIN test as b on a.appid = b.app_id and a.channelname = b.channelname and a.device_uuid = b.device_uuid WHERE a.realtime BETWEEN '2011-08-01 00:00:00' and '2011-08-31 23:59:59' and a.appid IN ('2x1kfBk63z','Gj9YiT','2S5Wcx','S4zbL7') and a.channelname IN ('dingfeng_news9','afyl_news4','afyl_news1') GROUP BY a.appid,a.channelname
将mysql中的数据导成外部文件,并且有相应的分隔符号
SELECT * FROM `2_mobile_session` WHERE realtime BETWEEN '2011-08-30 00:00:00' and '2011-08-30 23:59:59' INTO OUTFILE '/home/mysql/20110919_session.txt' fields terminated by ',' enclosed by '"' lines terminated by '\r\n';
导入数据库
load data local infile '/home/logs/remoteFiles/20110830_device.txt' into table 2_mobile_device character set utf8 fields terminated by ',' enclosed by '"' lines terminated by '\r\n'