Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SELECT
IF (u.user_id < 1000, u.employee_name, LCASE(u.employee_name)) AS employee_name,
u.user_id,
u.user_parameter_group,
s.mtd_shareamount,
l.mtd_original_loanproduction
FROM exp_dash_ops_users AS u
/* exp_dash_ops_daily_shares */
LEFT JOIN (
SELECT branch_id, user_id, SUM(share_amount) AS mtd_shareamount
FROM exp_dash_ops_daily_shares
WHERE opendate_month = <?php echo $month; ?>
GROUP BY user_id )
AS s ON s.user_id = u.user_id
/* exp_dash_ops_credit_card */
LEFT JOIN (
SELECT branch_id, user_id, COUNT(branch_id) AS mtd_creditcard
FROM exp_dash_ops_credit_card
WHERE opendate_month = <?php echo $month; ?>
GROUP BY user_id )
AS c ON c.user_id = u.user_id
/* exp_dash_ops_daily_loans */
LEFT JOIN (
SELECT branch_id, user_id, opendate_month, SUM(loan_original_amount) AS mtd_original_loanproduction, COUNT(branch_id) AS mtd_loancount
FROM exp_dash_ops_daily_loans
WHERE opendate_month = <?php echo $month; ?>
GROUP BY user_id )
AS l ON l.user_id = u.user_id
/* exp_dash_ops_gap_mmp */
LEFT JOIN (
SELECT user_id, branch_id
FROM exp_dash_ops_gap_mmp
WHERE opendate_month = <?php echo $month; ?>
GROUP BY user_id )
AS g ON g.user_id = u.user_id
WHERE (u.user_parameter_group = 0 AND u.user_id = <?php echo $uri_segments[6]; ?>) AND (s.user_id = u.user_id OR c.user_id = u.user_id OR l.user_id = u.user_id OR g.user_id = u.user_id)
GROUP BY u.user_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.