2019-03-13(新项目市场运行状态)

WITH tmp AS (select nf,zc,a.ggbs,b.ggmc,xmmc,sum(jsjyj_bq)/count(1) scj_bq

from "DM"."TM_YX_SCJGBB_Z_TH" a left join dm.td_gg b on a.ggbs = b.ggbs

where xmmc in ('江苏省','山东省' ,'安徽省' ,'上海市','浙江省',

'河南省','湖北省','湖南省','江西省','黑龙江省','吉林省','辽宁省','大连','北京市','天津市','河北省',

'内蒙古自治区','陕西省','山西省','甘肃省','宁夏回族自治区','青海省','新疆维吾尔自治区', '广东省','深圳',

'海南省','福建省','四川省','重庆市','贵州省','广西壮族自治区','云南省') and a.ggbs in ('6901028112789','6901028111324','6901028114455','6901028062015',

'6901028062350','6901028115445')

group by nf,zc,a.ggbs,b.ggmc,xmmc)

select sclx,xmmc,nf,zc,a.ggbs,a.ggmc,b.dxj,b.mbj,b.sxj,scj_bq,

CASE WHEN scj_bq

when (dxj<=scj_bq and scj_bq<= mbj) then 1.00*(15+(scj_bq-dxj)*(10/(mbj-dxj)))

    when (mbj<=scj_bq and scj_bq<= sxj) then 30

    WHEN scj_bq>dxj then 25

    ELSE 15  END FS

from tmp a LEFT JOIN dm.test_jg_1 b ON a.ggbs= b.ggbs AND a.xmmc=b.sfmc

WHERE xmmc='江苏省'

order BY nf,zc

你可能感兴趣的:(2019-03-13(新项目市场运行状态))