1

I have built cohorts of accounts based on date of first usage of our service. I need to use these cohorts in a handful of different queries, but don't want to have to create the queries in each of these downstream queries.
Reason: Getting the data the first time took more than 60 minutes, so i don't want to pay that tax for all the other queries.

I know that I could do a statement like the below:

WHERE  ACCOUNT_ID IN ('1234567','7891011','1213141'...) 

But, I'm wondering if there is a way to create a temporary table that I prepopulate with my data, something like

WITH MAY_COHORT AS ( SELECT ACCOUNT_ID  Account_ID, '1234567' Account_ID, '7891011' Account_ID, '1213141' )

I know that the above won't work, but would appreciate any advice or counsel here. thanks.

2 Answers 2

1

Unless I am missing something, you're already on the right track, just an adjustment to your CTE should work:

WITH MAY_COHORT AS ( SELECT Account_ID from TableName WHERE ACCOUNT_ID IN ('1234567','7891011','1213141'...) )

This should give you the May_Cohort table to use for subsequent queries.

Sign up to request clarification or add additional context in comments.

Comments

0

You can also use a sub-select for your Ids (no WITH MY_COHORT):

WHERE  ACCOUNT_ID IN (
          SELECT Account_ID 
            from TableName "Where ... your condition to build your cohort ..." )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.