SELECT
tccc.CODE AS "法人客户编码",
tccc.full_name AS "法人客户全称",
tbc.CODE AS "业务客户编码",
tbc.full_name_cn AS "业务客户全称",
tbc.short_name_cn AS "业务客户简称",
tbc.full_name_en AS "业务客户英文名称",
tbc.short_name_en AS "业务客户英文简称",
REPLACE ( REPLACE ( REPLACE ( tbc.brands, "11", "OPPO" ), "12", "OnePlus" ), "13", "realme" ) AS "所属品牌",
tbc.start_cooperation_date AS "起始合作日期",
tbc.change_request_status AS "业务客户状态",
tbc.stop_cooperation_date AS "停止合作日期",
CONCAT( tcc1.name_cn, ",", tcc2.name_cn, ",", tcc3.name_cn ) AS "客户类型",
tcc4.name_cn AS "渠道标签",
CASE
WHEN tbc.factory_certification = 1 THEN
'NKA'
WHEN tbc.factory_certification = 2 THEN
'T'
WHEN tbc.factory_certification = 3 THEN
'S'
WHEN tbc.factory_certification = 4 THEN
'A'
WHEN tbc.factory_certification = 5 THEN
'B'
WHEN tbc.factory_certification = 6 THEN
'C' ELSE ''
END AS "工厂认证等级",
tso.name AS "所属销售组织",
IF
( tbc.`online` = 1, "线上", "线下" ) AS "线上/线下",
tpt.terms_name AS "收款条件"
FROM
customer.business_customer tbc
INNER JOIN (
SELECT
tbcc.business_customer_id,
tbcc.corporate_customer_id
FROM
customer.business_corporate_customer tbcc
WHERE
tbcc.corporate_customer_id IN (
SELECT
id
FROM
customer.corporate_customer tcc
WHERE
tcc.CODE IN ( "10000566", "10000559", "90000330", "10000608", "10000589" )
AND deleted = 0
)) t1 ON tbc.id = t1.business_customer_id
LEFT JOIN customer.corporate_customer tccc ON tccc.id = t1.corporate_customer_id
LEFT JOIN base.payment_terms tpt ON tpt.terms_id = tbc.payment_terms_id
LEFT JOIN base.customer_classification tcc1 ON tcc1.CODE = tbc.customer_category
LEFT JOIN base.customer_classification tcc2 ON tcc2.CODE = tbc.customer_subcategory
LEFT JOIN base.customer_classification tcc3 ON tcc3.CODE = tbc.customer_subcategory
LEFT JOIN base.customer_classification tcc4 ON tcc4.CODE = tbc.channel_label
LEFT JOIN base.sales_organization tso ON tso.id = tbc.sales_organization