Skip to content

Instantly share code, notes, and snippets.

@agehlot
Created May 4, 2023 06:34
Show Gist options
  • Save agehlot/ae04e57b95f8023967f4390c63f39a04 to your computer and use it in GitHub Desktop.
Save agehlot/ae04e57b95f8023967f4390c63f39a04 to your computer and use it in GitHub Desktop.
CDP SQL query that selects customers where the sum of all their order totals is greater than 100
select g.meta_ref as guest_ref
from (select meta_guest_ref
from partners_sandbox.orders
where upper(partners_sandbox.orders.type) = upper('STANDARD')
group by meta_guest_ref
having SUM(partners_sandbox.orders.core_price) > 100.0) as o
inner join partners_sandbox.guests as g
on o.meta_guest_ref = g.meta_ref
group by g.meta_ref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment