zoukankan      html  css  js  c++  java
  • MySQL 案例:计算环比

    select a.day_num as "序号",
           a.create_time as "上架时间",
           a.clue_num as "上架车源量",
          ((a.clue_num/b.clue_num)-1) as "环比"
    from
    (
        select cast(date_diff('day',cast('2019-01-01' as timestamp),a.create_time) as int) as day_num,
               a.create_time,
               a.clue_num
        from
        (
              SELECT
               --substr(create_time,1,7) as year_mo,
               date(from_unixtime(to_unixtime(cast(create_time as timestamp)))) as create_time,
               cast(count(distinct clue_id) as double) as clue_num
              FROM guazi_dw_dwd.dim_com_car_source_ymd as a
              WHERE dt = CAST(date_add('day', -1, current_date) AS VARCHAR)
              and substr(create_time,1,10) between '${date1}' and '${date2}'
              AND platform in (2,3)
              group by 1
        )a
    )a
    left join
    (
        select cast(date_diff('day',cast('2019-01-01' as timestamp),a.create_time) as int) as day_num,
               a.create_time,
               a.clue_num
        from
        (
              SELECT
               --substr(create_time,1,7) as year_mo,
               date(from_unixtime(to_unixtime(cast(create_time as timestamp)))) as create_time,
               cast(count(distinct clue_id) as double) as clue_num
              FROM guazi_dw_dwd.dim_com_car_source_ymd as a
              WHERE dt = CAST(date_add('day', -1, current_date) AS VARCHAR)
              and substr(create_time,1,10) between '${date1}' and '${date2}'
              AND platform in (2,3)
              group by 1
        )a
    )b
    on a.day_num = b.day_num + 1
    order by 1 asc
  • 相关阅读:
    jQuery--百度百科
    JSP--百度百科
    servlet--百度百科
    java web--百度百科
    软件测试--百度百科
    HTML--百度百科
    CSS--百度百科
    JavaScript--百度百科
    js识别不同浏览器
    【cocos2dx开发技巧10】cocosStudio的集成以及c++11的新特性
  • 原文地址:https://www.cnblogs.com/lixiaozhi/p/11727087.html
Copyright © 2011-2022 走看看