我有以下脚本:
SELECT *
FROM (
SELECT distinct web_product_source_id, recipe_id, cos_score,
row_number() over (partition by web_product_source_id order by cos_score desc) as rnk
FROM (
SELECT web_product_source_id, recipe_id, max(cos_score) cos_score
FROM edw_sandbox.combined_with_product_details_ouput_cleaned
WHERE web_supercat_source_id = 'cookware'
GROUP BY 1,2
) a
) b
WHERE rnk <= 20
ORDER BY web_product_source_id, rnk;
我想在“WHERE”语句中添加一个 if else 语句。如果 web_product_source_id id 包含以下任何术语(“cookware”、“set”等...),我希望数据排名前 20 位或前 40 位
须藤代码:
if 'set' or 'cookware' in web_product_source_id id: pull top 40 ranks
else: pull top 20 ranks and cos_score >= .7