感谢各位大大来此一游!
首先 我有一组sql,都是查的同一张表,select 的条件不同
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 1 AND _platform = 4 GROUP BY DATE(_servertime) ;
SELECT DATE(_servertime),count(DISTINCT(_uid)) FROM ac_1500 WHERE _bt = 1501 AND _type = 1 AND _platform = 4 GROUP BY DATE(_servertime) ;
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 2 AND _platform = 4 GROUP BY DATE(_servertime);
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 3 AND _platform = 4 GROUP BY DATE(_servertime);
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 4 AND _platform = 4 GROUP BY DATE(_servertime);
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 5 AND _platform = 4 AND _mode LIKE 'iPhone%' GROUP BY DATE(_servertime);
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 5 AND _platform = 4 AND _mode LIKE 'iPad%' GROUP BY DATE(_servertime);
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 6 AND _platform = 4 GROUP BY DATE(_servertime);
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 8 AND _platform = 'iphone' GROUP BY DATE(_servertime);
SELECT DATE(_servertime),count(1) FROM ac_1500 WHERE _bt = 1501 AND _type = 8 AND _platform = 'android' GROUP BY DATE(_servertime);
我怎么能把这些sql组成一个sql。然后返回数据,
时间 第一个count的数据 第二个count的数据 第三个count的数据 ......
2015-1-28 20 30 40 ......
........
------解决思路----------------------
上面那个错了,这个应该差不多了
SELECT DATE(_servertime),
count(case when _bt = 1501 AND _type = 1 AND _platform = 4 then 1 else null end),
count(DISTINCT case when _bt = 1501 AND _type = 1 AND _platform = 4 then uid else null end),
count(case when _bt = 1501 AND _type = 2 AND _platform = 4 then 1 else null end),
count(case when _bt = 1501 AND _type = 3 AND _platform = 4 then 1 else null end),
count(case when _bt = 1501 AND _type = 4 AND _platform = 4 then 1 else null end),
count(case when _bt = 1501 AND _type = 5 AND _platform = 4 AND _mode LIKE 'iPhone%' then 1 else null end),
count(case when _bt = 1501 AND _type = 5 AND _platform = 4 AND _mode LIKE 'iPad%' else null end),
count(case when _bt = 1501 AND _type = 6 AND _platform = 4 then 1 else null end),
count(case when _bt = 1501 AND _type = 8 AND _platform = 'iphone' then 1 else null end),
count(case when _bt = 1501 AND _type = 8 AND _platform = 'android' then 1 else null end),
FROM ac_1500
where _bt = 1501 and _type in (1,2,3,4,5,6,8) and _platform in (4,'iphone','android')
GROUP BY DATE(_servertime) ;