Last active
December 12, 2015 12:39
-
-
Save caseydentinger/4773248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select sql_no_cache o.* | |
from (select * from orders where orders_status = 1) o | |
where ( | |
select count(*) from orders_products op | |
join products p on op.products_id = p.products_id | |
join parts pa on p.products_id = pa.products_id | |
where op.products_quantity > ( | |
p.products_physical_quantity - ifnull( | |
( | |
select sum(rs.quantity) | |
from (select * from orders where orders_status in (1, 5)) o | |
join reserved_stock rs on o.orders_id = rs.order_id | |
where rs.part_id = pa.parts_id | |
), 0) | |
) | |
and op.orders_id = o.orders_id | |
) = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is slower, but I think more readable and extensible. Hope this helps.