How can I reduce table scan time in snowflake

23 Views Asked by At
SELECT
    key,
    MAX(CASE WHEN LOWER(product) = 'electronics' AND LOWER(sub_pr) = 'tv' THEN first_dt_bought END) AS first_dt_bought_tv,
    MIN(CASE WHEN LOWER(product) = 'electronics' AND LOWER(sub_pr) = 'tv' THEN first_dt END) AS first_dt_tv,
    MIN(CASE WHEN LOWER(product) = 'electronics' AND LOWER(sub_pr) = 'tv' THEN amt END) AS first_amt_tv,
    MIN(CASE WHEN LOWER(product) = 'fruit' AND LOWER(sub_pr) = 'apple' THEN first_dt_bought END) AS first_dt_bought_apple,
    MIN(CASE WHEN LOWER(product) = 'fruit' AND LOWER(sub_pr) = 'apple' THEN first_dt END) AS first_dt_apple,
    MIN(CASE WHEN LOWER(product) = 'fruit' AND LOWER(sub_pr) = 'apple' THEN amt END) AS first_amt_apple
FROM contacts 
where (product IN('fruit','electronics')) OR (sub_pr IN('tv','apple'))
GROUP BY 1;

How can I rewrite this logic in a better way to reduce table scan time

0

There are 0 best solutions below