SQL例項 寫一段業績的SQL,HIVE端

2021-10-04 16:34:35 字數 4550 閱讀 6469

select agent.corp_name as

`品牌名稱`

, agent.shop_name as

`門店名稱`

, ca.shop_ca_name as

`對應ca`

, agent.agent_code as

`經紀人系統號`

, agent.agent_name as

`經紀人姓名`

, nvl(perfnum.perf_num,0)

as`二手單量`

, nvl(perf.performance,0)

as`二手業績`

, nvl(perf_n.perf_n_num,0)

as`新房單量`

, nvl(perf_n.performance,0)

as`新房業績`

, nvl(nvl(perfnum.perf_num,0)

+ nvl(perf_n.perf_n_num,0)

,0)as

`合計單量`

, nvl(nvl(perf.performance,0)

+ nvl(perf_n.performance,0)

,0)as

`合計業績`

, house.hold_house as

`維護**數量`

, house.prospect as

`實勘量`

, house.

comment

as`房評量`

, im.im_nub as

`im進線量`

, im.im_min as

`im一分鐘量`

from

(select agent_ucid, agent_code, agent_name, corp_code, corp_name

, shop_code, shop_name, on_job_days, is_zero_showing_cnt_lst7d, is_zero_showing_cnt_lst30d

from dwd.dwd_coo_***

where pt =

'20200505000000'

and on_job_status_code =

170007002

and brand_code in

(990004005

,990004002

)) agent

left

join

(select role_ucid,

sum(assign_amt)

as performance

from olap.olap_***

*where pt =

'20200505000000'

and catagory_name =

'應收業績'

and settle_month = substr(

'20200505000000',1

,6)and is_valid =

1group

by role_ucid

) perf

on agent.agent_ucid = perf.role_ucid

left

join

(select role_ucid,

sum(assign_amt)

as performance,

count

(distinct agreement_id)

as perf_n_num

from olap.olap_nh_hr_performance_***

*where pt =

'20200505000000'

and role_type_name =

'主成交經紀人'

and substr(create_time,1,

7)= substr(

'20200505000000',1

,6)and assign_amt >

0group

by role_ucid

) perf_n

on agent.agent_ucid = perf_n.role_ucid

left

join

(select sign_ucid,

sum(

case

when del_type =

'買賣'

then

1else

0end

)as perf_num

from rpt.rpt_coo_***

*where pt =

'20200505000000'

and substr(sign_date,1,

7)= substr(

'20200505000000',1

,6)and

status

<>

'合同-解約'

group

by sign_ucid

) perfnum

on perfnum.sign_ucid = agent.agent_ucid

left

join

(select sub_brand_name, shop_code, shop_name, area_name, shop_ca_name

, shop_agent_cnt

from olap.olap_***

*where pt =

'20200505000000'

and length(shop_ca_name)

<>

0and is_valid =

1and length(shop_first_del_time)

<>

0) ca

on ca.shop_code = agent.shop_code

left

join

(select hold_ucid,

count

(city_code)

as hold_house,

count

(case

when is_prospecting_housedel =

'是'then

'1'else

null

end)

as prospect

,count

(case

when is_housedel_comment =

'是'then

'1'else

null

end)

ascomment

from rpt.rpt_***

*where pt =

'20200505000000'

and del_type =

'買賣'

groupby1

) house

on house.hold_ucid = agent.agent_ucid

left

join

(select employee_no,

count

(city_code)

as im_nub,

count

(case

when is_60s_response =

'是'then

1else

null

end)

as im_min

from rpt.rpt_comp***

*where pt <=

'20200505000000'

and pt >= concat(substr(

'20200505000000',1

,6),

'01000000'

)and if_in_nine_to_twentytwo =

'是'and is_closed =

'否'groupby1

) im

on im.employee_no = agent.agent_code

left

join

(select employee_no,

count

(city_code)

as tel_nub,

count

(case

when is_succeed =

'是'then

1else

null

end)

as tel_on

from rpt.rpt_rpt_***

*where pt <=

'$'and pt >= concat(substr(

'$',1,

6),'01000000'

)and is_connect =

'是'and is_closed =

'否'and if_in_nine_to_twentytwo =

'是'groupby1

) tel

on tel.employee_no = agent.agent_code

order

by`合計業績`

desc

一段SQL指令碼

create table gc col1 char 10 drop table gc 處理引數 declare str varchar 100 select str 1,2,3,4,5 插入處理 declare s varchar 8000 select s select replace str,u...

一段寫火箭姚明的古詩

color greens 火箭連勝,扁鵲見姚明,視其腿,觀其足,良久,扁鵲曰 君有傷在舟骨,已然萌動,不治將恐深。姚明曰 今戰事吃緊,前有湖人不可一世,後有勇士虎視眈眈,焉能休也。且吾攻可肆虐籃筐,守可拒敵千里。稍不適,無小痛,身為主將焉能怠也!此不足為他人道也。扁鵲搖頭出,姚明曰 醫之善意吾之幸也...

一段SQL語句(涉及游標)

建立臨時表 create table people pname nvarchar 30 insert people values 4479 insert people values 542 insert people values 543 declare randdate datetime,rand...