select __T1.AREA_CODE as ID, area1.AREA_NAME as provinceName, area2.AREA_NAME as cityName, area3.AREA_NAME as disinctName, case when area1.AREA_NAME = area2.AREA_NAME then area1.AREA_NAME when area2.AREA_NAME = area3.AREA_NAME then area1.AREA_NAME + '/' + area2.AREA_NAME else area1.AREA_NAME + '/' + area2.AREA_NAME+ '/' + area3.AREA_NAME end as areaName FROM ss_sys_area __T1 left join ss_sys_area area1 on area1.AREA_CODE = left(__T1.AREA_CODE ,2) + '0000' and area1.TENANT_ID = '1a8b15af-830f-4f30-8ae8-a43a7bb454f7' left join ss_sys_area area2 on area2.AREA_CODE = left(__T1.AREA_CODE ,4) + '00' AND area2.TENANT_ID = '1a8b15af-830f-4f30-8ae8-a43a7bb454f7' left join ss_sys_area area3 on area3.AREA_CODE = __T1.AREA_CODE AND area3.TENANT_ID = '1a8b15af-830f-4f30-8ae8-a43a7bb454f7' where __T1.TENANT_ID = '1a8b15af-830f-4f30-8ae8-a43a7bb454f7'
标签:__,CODE,NAME,AREA,拼接,行政区划,area1,area2 From: https://www.cnblogs.com/privateLogs/p/18191477