-
-
Save MightyBlow/a4082fb8159fb894aa00d941e815fc11 to your computer and use it in GitHub Desktop.
.sh
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 DISTINCT | |
loan_app.id, | |
ee."label" AS delivery_product, | |
product.name AS cash_loan_product | |
FROM | |
loan_delivery ld | |
JOIN | |
external_entity ee ON ld.creditproduct_id = ee.id | |
INNER JOIN | |
dblink( | |
'host=apix-p-db-pg-slave.domrfbank.ru user=*** password=*** dbname=prod-ahml-loan-app'::text, | |
'select id, status, created_at from orders'::text | |
) loan_app(id integer, status text, created_at timestamp) ON ld.source_id::integer = loan_app.id | |
INNER JOIN | |
dblink( | |
'host=apix-p-db-pg-slave.domrfbank.ru user=*** password=*** dbname=prod-ahml-product'::text, | |
'select name from cash_loan_product'::text | |
) product(name text) ON TRUE | |
WHERE | |
CAST(loan_app.created_at AS date) = current_date | |
AND ld.status NOT IN ('DEAL_CANCELED') | |
AND loan_app.status IN ('LOAN_ISSUED') | |
AND ee.label != product.name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment