Created
February 19, 2017 16:05
-
-
Save anonymous/b497f6a379d26532144ac13bd5fde20e 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 | |
mm.`user_id`, | |
u.`name` , | |
mm.`group_id`, | |
g.`group_name`, | |
p.`party_id`, p.`party_name`,p.`party_cost` , | |
@amount_paid := | |
( | |
SELECT IF(SUM(product_cost) IS NULL, 0, SUM(product_cost)) | |
FROM `party_budget_detail` | |
WHERE `party_id`=p.`party_id` AND purchased_by=u.`user_id` | |
) AS amount_paid, | |
@member_count := | |
( | |
SELECT COUNT(user_id) AS count_ | |
FROM member_management | |
WHERE group_id = mm.`group_id` | |
) AS member_count, | |
@share_price := p.party_cost/@member_count AS share_price, | |
@amount_paid - @share_price AS due_amount | |
FROM `member_management` AS mm INNER JOIN | |
`users` AS u | |
ON mm.`user_id` = u.`user_id` | |
INNER JOIN `group` AS g | |
ON mm.`group_id` = g.`group_id` | |
INNER JOIN `parties` AS p | |
ON p.`group_id` = g.`group_id` | |
WHERE party_id=63 ORDER BY p.party_id; | |
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 | |
mm.`user_id`, | |
u.`name` , | |
mm.`group_id`, | |
g.`group_name`, , p.`party_name`,p.`party_cost` , | |
( | |
SELECT IF(SUM(product_cost) IS NULL, 0, SUM(product_cost)) | |
FROM `party_budget_detail` | |
WHERE `party_id`=p.`party_id` AND purchased_by=u.`user_id` | |
) AS amount_paid, | |
amount_paid/5 | |
FROM `member_management` AS mm INNER JOIN | |
`users` AS u | |
ON mm.`user_id` = u.`user_id` | |
INNER JOIN `group` AS g | |
ON mm.`group_id` = g.`group_id` | |
INNER JOIN `parties` AS p | |
ON p.`group_id` = g.`group_id` WHERE party_id=63 ORDER BY p.party_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment