Here is something I'm running into that I'm wondering if anyone else has solved: I'm building lists of companies, then finding people who match certain titles at those companies. The issue is that in some cases I get a TON of people at 1 company e.g. 10 people at 1 company and I don't want to reach out to all of them just yet. Is there a way to say "only get the contact information of x people at Company A" without delete the other people from the table?
ExclusionLogic AS (
SELECT
*,
count_per_account
FROM
FilteredRecords
WHERE
count_per_account <= 5 -- Only include accounts with ≤ 5 entries
),
ModifiedRecords AS (
SELECT
TRIM(
REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(
string_field_0,
r'(?i)\b(INC|LTD|LIMITED|CORP|CORPORATION|LLC)(\.\s*|,\s*|\s*)\b',
''
),
r',\s*$', ''
),
r'\s+\.$',
''
)
) AS cleaned_string_field_0,
*, -- Includes all other original fields
ROW_NUMBER() OVER (
PARTITION BY
TRIM(
REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(
UPPER(string_field_0),
r'(?i)\b(INC|LTD|LIMITED|CORP|CORPORATION|LLC)(\.\s*|,\s*|\s*)\b',
''
),
r',\s*$', ''
),
r'\s+\.$',
''
)
)
ORDER BY string_field_1 -- This should be tailored to your data schema
) AS rn
FROM
ExclusionLogic
)
SELECT
cleaned_string_field_0 AS string_field_0,
* EXCEPT(string_field_0, rn, count_per_account) -- Excludes intermediate calculation fields
FROM
ModifiedRecords
WHERE
rn <= 5;This may be the solution


Posted using /giphy
the problem is sometimes you want to limit the Decision makers first and then move down the line.
yeah that's facts
"Give me the 5 most senior people"
which part filters for seniority?