sql实现同环比(同比,环比)

sql实现同比,环比sql

环比同比用于描述统计数据的变化状况。微信

公式:flex

     同比增加率=(本期数-同期数)÷同期数×100%

SQL图片示例:
spa


SQL代码:.net


  1. select 3d

  2. t1.ptdatecode

  3. ,t1.areaorm

  4. ,t1.goods_nameblog

  5. ,t1.income图片

  6. ,ifnull(t1.income,0)/ifnull(t2.income,0)-1 as year_on_year_income

  7. ,t1.user_count

  8. ,ifnull(t1.user_count,0)/ifnull(t2.user_count,0)-1 as year_on_year_user_count

  9. ,'同比' as mark

  10. from bdl_goods_income_public t1

  11. join bdl_goods_income_public t2

  12. on(t1.area=t2.area and t1.goods_name=t2.goods_name and t2.ptdate=DATE_SUB('2019-04-22',INTERVAL 6 day))

  13. where t1.area ='china'

  14. and t1.ptdate = '2019-04-22'

  15. union all

  16. select

  17. t1.ptdate

  18. ,t1.area

  19. ,t1.goods_name

  20. ,t1.income

  21. ,0 as year_on_year_income

  22. ,t1.user_count

  23. ,0 as year_on_year_user_count

  24. ,'核对数据' as mark

  25. from bdl_goods_income_public t1

  26. where t1.area ='china'

  27. and ptdate=DATE_SUB('2019-04-22',INTERVAL 6 day)

  28. ;


 同比环比公式

 



本文分享自微信公众号 - SQL数据分析(dianwu_dw)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。

相关文章
相关标签/搜索