Skip to content

Instantly share code, notes, and snippets.

@nfarah86
Created February 24, 2021 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfarah86/1dd1d08701ef228755ae3c52985b0ea7 to your computer and use it in GitHub Desktop.
Save nfarah86/1dd1d08701ef228755ae3c52985b0ea7 to your computer and use it in GitHub Desktop.
Percentage of sales of customers who bought capris tights and a top
with hits as (
SELECT
count(*) totalTopAndCaprisPurchased
FROM
commons.customerActivity ca
WHERE
length(
ARRAY_INTERSECT(
ca.AddedToShoppingCart,
ARRAY_CREATE('pkrcapris', 'pkrtop')
)
) = 2
),
totals as (
SELECT
COUNT(*) as allPurchases
FROM
commons.customerActivity ca
)
SELECT
Cast(h.totalTopAndCaprisPurchased as float) / cast(t.allPurchases as float) * 100
FROM
hits h,
totals t
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment