File tree Expand file tree Collapse file tree
services/libs/data-access-layer/src/affiliations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,16 +33,23 @@ export async function findWorkExperiencesBulk(
3333) : Promise < IWorkRow [ ] > {
3434 const rows : IWorkRow [ ] = await qx . select (
3535 `
36- WITH aggs AS (
36+ WITH relevant_orgs AS (
37+ SELECT DISTINCT "organizationId"
38+ FROM "memberOrganizations"
39+ WHERE "memberId" IN ($(memberIds:csv))
40+ AND "deletedAt" IS NULL
41+ ),
42+ aggs AS (
3743 SELECT
3844 osa."organizationId",
3945 sum(osa."memberCount") AS total_count
4046 FROM "organizationSegmentsAgg" osa
41- WHERE osa."segmentId" IN (
42- SELECT id FROM segments
43- WHERE "grandparentId" IS NOT NULL
44- AND "parentId" IS NOT NULL
45- )
47+ WHERE osa."organizationId" IN (SELECT "organizationId" FROM relevant_orgs)
48+ AND osa."segmentId" IN (
49+ SELECT id FROM segments
50+ WHERE "grandparentId" IS NOT NULL
51+ AND "parentId" IS NOT NULL
52+ )
4653 GROUP BY osa."organizationId"
4754 )
4855 SELECT
You can’t perform that action at this time.
0 commit comments