Skip to content

Instantly share code, notes, and snippets.

@scottdriscoll
Created March 18, 2015 23:53
Show Gist options
  • Save scottdriscoll/f813eee71bb5800c6956 to your computer and use it in GitHub Desktop.
Save scottdriscoll/f813eee71bb5800c6956 to your computer and use it in GitHub Desktop.
missing folding type
select distinct on (rr.order_id) rr.order_id, cat.title from rr_sku_cat cat
inner join rr_transactions rr on rr.sku_cat_id = cat.id
where rr.order_id in (
select id from (
select o.id,
(select count(v.id) from order_item_option_value v inner join order_items oi on v.order_item_id = oi.id where oi.order_id = o.id and v.option_value_id in (103,106)) as folding_option_count,
(select count(v2.id) from order_item_option_value v2 inner join order_items oi2 on v2.order_item_id = oi2.id where oi2.order_id = o.id and v2.option_value_id in (10,11,12)) as folding_count
from orders o
inner join order_items oi3 on o.id = oi3.order_id
where o.payment_status = 1 and
o.date_ordered between '2/23/2015' and now() and
oi3.product_id in (5,73)) as foo
where folding_count = 0 and folding_option_count > 0)
and rr.sku_id = 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment