-- Databricks notebook source
-- DBTITLE 1,产品挂中文名


--Product中文名字,若有超过5个CORP或者MANU生产，则将其报告上排序的优先级调低
insert overwrite table tmp.tmp_ims_td_prod_tmp 
SELECT DISTINCT PROD.PROD_COD
	FROM dws.dws_ims_td_prod_cn PROD
	LEFT JOIN dwd.dwd_ims_td_pack_property PACK
		ON PROD.PROD_COD = PACK.PROD_COD
	LEFT JOIN dws.dws_ims_td_corp_cn CORP
		ON PACK.CORP_COD = CORP.CORP_COD
	WHERE PROD.PROD_DES_C IN 
	(
	--先计算出超过10个厂家生产的Prod_CN
	
	--先计算出有多个厂家生产的Prod_CN
		SELECT PROD.PROD_DES_C
		FROM dwd.dwd_ims_td_pack_property PACK
		LEFT JOIN dws.dws_ims_td_prod_cn PROD
			ON PACK.PROD_COD = PROD.PROD_COD 
		GROUP BY PROD.PROD_DES_C
		HAVING ( COUNT(DISTINCT CORP_DES) > 5 OR COUNT(DISTINCT MANU_DES) > 5 )
			AND PROD.PROD_DES_C IS NOT NULL
     );


-- COMMAND ----------

UPDATE dws.dws_ims_td_prod_cn SET RANK_TYPE = 0 where PROD_COD in (
	SELECT DISTINCT PROD_COD FROM tmp.tmp_ims_td_prod_tmp
 );