Created
January 25, 2018 09:43
-
-
Save mmajorov/3b5c30ba9fc182df25fb2342666bfdad 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
CREATE OR REPLACE VIEW v_clients_requests_loans | |
AS | |
SELECT | |
req.id, | |
req.store_id, | |
req.client_id, | |
IFNULL(clients.initial_total_loan_limit > 0 OR clients.total_loan_limit > 0, 0) AS client_limit, | |
clients.mobile_phone AS client_phone, | |
DATE_ADD(req.created_at, INTERVAL 3 HOUR) AS created_at, | |
DATE_ADD(req.updated_at, INTERVAL 3 HOUR) AS updated_at, | |
IFNULL(client_new, 0) AS client_new, | |
req.status = 'claimed' OR loan_applications.status IN ('approved', 'rejected', 'finished') AS finished, | |
utm_source, | |
loan_application_id, | |
order_id, | |
IFNULL(client_new = 1 AND loan_applications.status IN ('approved', 'rejected', 'finished'), 0) AS first_payable, | |
req.decision, | |
device_type, | |
device_name, | |
city, | |
referer | |
FROM online_loan_requests AS req | |
LEFT JOIN clients ON client_id = clients.id | |
LEFT JOIN loan_applications ON loan_application_id = loan_applications.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment