数据统计分析中的几点
2019獨角獸企業重金招聘Python工程師標準>>>
1.在mysql 語句中,
?1.1?date_format(t.create_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')? 在這種情況是管用的。
?1.2 date_format(t.create_time,'%Y-%m') >= str_to_date(#{startTime,'%Y-%m'}) 這種不管用,改成下面的情況就管用了
?1.3 date_format(t.create_time,'%Y-%m') >= date_format(#{startTime},'%Y-%m')
2. 數據統計效率分析?
? 2.1 總重量和占比方式一
SELECT ROUND(b.total_weight/1000,3) ,ROUND((a.recy_weight/b.total_weight)*100,2) FROM?
(SELECT ?SUM(t.net_weight) recy_weight from t_sort_account t?
LEFT JOIN t_sell_category sc on sc.id = t.category_id
WHERE sc.is_recyclable = 1 and t.`status` = 1) a ,
(SELECT SUM(t.net_weight) total_weight from t_sort_account t?
WHERE t.`status` = 1) b?
2.2 總重量和占比方式二
SELECT ROUND(SUM(t.net_weight)/1000,3) total_weight,
SUM(IF(sc.is_recyclable = 1,t.net_weight,0))/SUM(t.net_weight) *100 recy_rate
??from t_sort_account t?
LEFT JOIN t_sell_category sc on sc.id = t.category_id
where t.status = 1
3. 在數據統計中對view 得應用
? ?當統計中鏈接表太多得時候,數據查詢慢
可以通過中間橋接一張視圖表,直接關聯視圖,去查詢,這樣可以提高效率
4. 在查詢的過程中,通過left join 鏈接表的過濾字段寫在 on 后面比加到where 中數據效率提升很多,項目中有一個在where 寫是 22秒,在on 中寫是2.24
5. mysql 中數據環比統計的想法
? ?查詢出一段時間的數據,因環比的計算公式為: (本期 - 上期)/上期* 100%,只有第一條數據沒有上期的數據,所以單獨查出上期數據。
? 通過后臺計算,有按日、按周、按月
轉載于:https://my.oschina.net/kuchawyz/blog/2990763
總結
以上是生活随笔為你收集整理的数据统计分析中的几点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 机器之心公开演讲:如何用AI技术传播AI
- 下一篇: 体素科技:2018年,算法驱动下的医学影