Created
July 24, 2014 18:10
-
-
Save werty1st/ceefffbdf509d05ca4ab to your computer and use it in GitHub Desktop.
mysql join IF sum
This file contains hidden or 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 ci.inventory_id, ci.inventory_quantity, cd.reservations, (ci.inventory_quantity + cd.reservations) as gesamt | |
FROM catalog_inventory ci | |
JOIN | |
(SELECT cd.documentation_inventory_nr, SUM(IF(cd.documentation_on >= UNIX_TIMESTAMP(NOW()),cd.documentation_quantity,0)) as reservations | |
FROM | |
catalog_documentation cd | |
GROUP BY cd.documentation_inventory_nr) as cd | |
ON cd.documentation_inventory_nr=ci.inventory_id | |
GROUP BY ci.inventory_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment