Created
March 28, 2014 11:43
-
-
Save said-and-done/e3e7a68fc2c84068d94a to your computer and use it in GitHub Desktop.
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 salesperson_id, | |
Sum(sold / salesperson_count) AS amount | |
FROM project_items | |
JOIN(SELECT allocation.project_item_id, | |
sold, | |
salesperson_id | |
FROM project_item_sellers | |
JOIN(SELECT project_item_id, | |
Sum(amount) AS sold | |
FROM project_item_allocations AS allocation | |
WHERE Year(allocation.created) = 2014 | |
AND Month(allocation.created) = 03 | |
GROUP BY project_item_id | |
HAVING sold <> 0 | |
) allocation | |
ON allocation.project_item_id = | |
project_item_sellers.project_item_id | |
GROUP BY allocation.project_item_id, salesperson_id | |
) t2 | |
ON t2.project_item_id = project_items.id | |
GROUP BY salesperson_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment