-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed companies / company pages from name to domain
- Loading branch information
Showing
5 changed files
with
62 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,38 @@ | ||
SELECT | ||
c.name AS company_name, | ||
ad.domain, | ||
COALESCE( | ||
cc.name, | ||
c.name, | ||
ad.domain | ||
) AS parent_company_name | ||
WITH mytree AS ( | ||
SELECT | ||
c.name AS company_name, | ||
ad.domain AS company_domain, | ||
COALESCE( | ||
parad.domain, | ||
ad.domain | ||
) AS parent_company_domain, | ||
COALESCE( | ||
cc.name, | ||
c.name, | ||
ad.domain | ||
) AS parent_company_name | ||
FROM | ||
adtech.companies AS c | ||
LEFT JOIN adtech.companies AS cc | ||
ON | ||
c.parent_company_id = cc.id | ||
LEFT JOIN adtech.company_domain_mapping AS cdm | ||
ON | ||
c.id = cdm.company_id | ||
LEFT JOIN adtech.company_domain_mapping AS pcdm | ||
ON | ||
cc.id = pcdm.company_id | ||
FULL OUTER JOIN ad_domains AS ad | ||
ON | ||
cdm.domain_id = ad.id | ||
LEFT JOIN ad_domains AS parad | ||
ON | ||
pcdm.domain_id = parad.id | ||
) | ||
|
||
SELECT * | ||
FROM | ||
adtech.companies AS c | ||
LEFT JOIN adtech.companies AS cc | ||
ON | ||
c.parent_company_id = cc.id | ||
LEFT JOIN adtech.company_domain_mapping AS cdm | ||
ON | ||
c.id = cdm.company_id | ||
FULL OUTER JOIN ad_domains AS ad | ||
ON | ||
cdm.domain_id = ad.id | ||
mytree | ||
WHERE | ||
c.name = :company | ||
OR cc.name = :company | ||
OR ad.domain ILIKE :company || '%'; | ||
company_domain = :company_domain | ||
OR parent_company_domain = :company_domain; |