Last active
November 19, 2019 22:52
-
-
Save naranjja/169b72251952ea5896b16dc29b49848a to your computer and use it in GitHub Desktop.
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
create temp table user_info as | |
select A.*, B.sends_to_role | |
from users as A | |
left join role_plans as B on A.role_id = B.role_id | |
where 1 = 1 | |
and (A.id = '{user_id}' or A.sap_id = '{user_id}') | |
and A.doc_id = '{doc_id}' | |
and A.is_active = true; | |
select A.id, A.name_1, A.surname_1, B."name" as company_name, B.id as company_id, A.role_id | |
from users as A | |
left join companies as B on A.company_id = B.id | |
where 1 = 1 | |
and A.role_id in (select unnest(sends_to_role) from user_info) | |
and A.is_active = true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment