发表于: 2018-03-27 23:23:57

0 578


今天完成的任务

1、分析接口返回的数据结构

看下面的原型,饼图的展示内容包括某项(年龄段15-20、20-25这种)、某项人数(鼠标挪到饼图不同区域,会显示该区域具体人数)、总人数(计算百分比)


上面的返回结构,跟折线图的很像,所以使用JDBCTemplate实现饼图功能时,SQL返回的数据也要包装成一个对象List:


2、写饼图的sql

饼图可以按下一条件对查询结果进行筛选

入参的话,就是对应的minPassAt、maxPassAt、occupationId、condition四个。难点在于按条件进行筛选。


方案是根据不同的条件,编写5条sql语句:按年龄、按籍贯、按学历、按专业、按毕业院校。


A、按年龄(用到了 case when 函数):

select a.item item, count(a.item) number FROM (select case when TIMESTAMPDIFF(year,born_at,CURRENT_TIMESTAMP()) >= 15 and TIMESTAMPDIFF(year,born_at,CURRENT_TIMESTAMP()) < 20 then '15-20' when TIMESTAMPDIFF(year,born_at,CURRENT_TIMESTAMP()) >= 20 and TIMESTAMPDIFF(year,born_at,CURRENT_TIMESTAMP()) < 25 then '20-25' end as item from record) a group by a.item ORDER BY number desc limit 0, 10


B、按籍贯(这个最麻烦,要对结果进行4次加工,剃掉籍贯中的字符串:“省”、“县”、“区”、“市辖区”):

select d.city item, count(d.city) number from (select SUBSTRING_INDEX(c.city,'省',-1) city from (select SUBSTRING_INDEX(b.city,'区',-1) city from (select SUBSTRING_INDEX(CONCAT(a.city),'市辖区',1) city from (select SUBSTRING_INDEX(CONCAT(province, city),'县',1) city from record) a) b) c) d group by city


C、按学历

select grade item, IFNULL(count(id), 0) number from record where status = 3 GROUP BY grade;


D、按专业

select city item, IFNULL(count(id), 0) number from record where status = 3 GROUP BY major ORDER BY number limit 0, 10;


E、按毕业院校

select school item, count(id) number from record where status = 3 group by school order by number desc limit 0, 10


遇到的问题

写SQL的时候琢磨了比较久


收获

写SQL比之前熟练了一下


明天的计划

1、完成饼图接口

2、完成导出Excel接口

3、改2个BUG


进度

demo时间 3月30号晚8点


返回列表 返回列表
评论

    分享到