1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| select address `地区`, date_format(udate,'yyyy-mm') `月份`, count(case when sex='male' then id end) `男性人数`, count(case when sex='female' then id end) `女性人数` from user_info group by address, date_format(udate, 'yyyy-mm') order by `地区`,`月份`;
select address `地区`, map("青", count(if(s_info.systemtype = 'android' and ((sex = 'male' and age < 35) or (sex = 'female' and age < 35)), 1, null)), "中", count(if(s_info.systemtype = 'android' and ((sex = 'male' and age between 35 and 65) or (sex = 'female' and age between 35 and 55)), 1, null)), "老", count(if(s_info.systemtype = 'android' and ((sex = 'male' and age > 65) or (sex = 'female' and age > 55)), 1, null)) ) `安卓使用人数`, map( "青", count(if(s_info.systemtype = 'ios' and ((sex = 'male' and age < 35) or (sex = 'female' and age < 35)), 1, null)), "中", count(if(s_info.systemtype = 'ios' and ((sex = 'male' and age between 35 and 65) or (sex = 'female' and age between 35 and 55)), 1, null)), "老", count(if(s_info.systemtype = 'ios' and ((sex = 'male' and age > 65) or (sex = 'female' and age > 55)), 1, null)) ) `ios使用人数` from user_info group by address;
select address `地区`, s_info.education `学历`, collect_list(s_info.phonebrand) `手机品牌列表` from user_info group by address, s_info.education;
with brand_counts as ( select lev, s_info.phonebrand as phonebrand, count(*) as cnt from user_info where s_info.phonebrand is not null group by lev, s_info.phonebrand ) select lev, str_to_map(concat_ws(',', collect_list(concat(phonebrand, ':', cnt)))) as phonebrand_list from brand_counts group by lev;
|