Last active
July 17, 2017 11:42
-
-
Save StaverDmitry/fb2757a81a59a426bc51c8785866407c 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 p.id, par.first_name ||' '|| par.last_name AS partners_name, | |
c.first_name ||' '|| c.last_name AS customers_name, | |
en_c.first_name ||' '|| en_c.last_name AS enquiry_customers_name, | |
coalesce(par.first_name||par.last_name, c.first_name||c.last_name, en_c.first_name||en_c.last_name, 'test') AS result | |
FROM passengers p | |
LEFT JOIN customers c ON p.customer_id = c.id | |
LEFT JOIN partners par ON p.partner_id = par.id | |
JOIN enquiries e ON p.enquiry_id = e.id | |
JOIN customers en_c ON e.customer_id = en_c.id | |
ORDER BY coalesce(par.first_name||' '||par.last_name, c.first_name||' '||c.last_name, en_c.first_name||' '||en_c.last_name) | |
LIMIT 20000; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment