t1和t2临时表单独查数据都是对的,合起来查数据多好几倍

Latty 发布于 2022-3-23 20:12 (编辑于 2022-3-23 20:16)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
CD20160914Lv8专家互助
发布于2022-3-23 20:13

select 2 `NO`,

   year(t1.complaintDate),

    sum(t1.数量)/sum(t2.总数量)*1000000 as 'PPM',

     sum(t1.数量),sum(t2.总数量),

     t1.日期维度,t1.base2

from

    (

select sum(countInPpmQty) as '数量',

     base2,

     case

        when '${baseway}' = '年' then  date_format(complaintDate, '%Y')

        when '${baseway}' = '季度' then concat(quarter(complaintDate),'季度')

        when '${baseway}' = '月' then concat(date_format(complaintDate, '%m'),'月')

        when '${baseway}' = '周' then concat(year(complaintDate),'年',week(complaintDate),'周')

        when '${baseway}' = '天' then  complaintDate 

        end as '日期维度'

from

   ( select *,  case when modulesite like '%上海%' then 'SH'

         when modulesite like '%深圳%' then 'SZ'  end as base2

         from ads_zxyclzl_kpi02_total_ppm_summary)ttt

    where complaintDate>='${startdate}'

    and complaintDate<='${enddate}'

group by 2,3,4

            )t1

left join 

(

    select

        sum(quantity) as 总数量,

        moduleorigin,

        case

        when '${baseway}' = '年' then  date_format(concat(shipment_date,'-01'), '%Y')

        when '${baseway}' = '季度' then concat(quarter(concat(shipment_date,'-01')),'季度')

        when '${baseway}' = '月' then concat(date_format(concat(shipment_date,'-01'), '%m'),'月')

        when '${baseway}' = '周' then concat(year(concat(shipment_date,'-01')),'年',week(concat(shipment_date,'-01')),'周')

        when '${baseway}' = '天' then  shipment_date 

        end as '日期维度'

    from

        ods_zxyclzl_totalshipments_fr

    where

        1 = 1

        and left(shipment_date,7)>= left('${startdate}',7)

            and left(shipment_date,7)<= left('${enddate}',7)

            group by 2,3,4

            )t2

                on t1.日期维度=t2.日期维度 

                and t1.base2=t2.moduleorigin

  • 2关注人数
  • 206浏览人数
  • 最后回答于:2022-3-23 20:16
    请选择关闭问题的原因
    确定 取消
    返回顶部