Skip to content

PostgreSQL equivalent of Pandas outer merge

I am trying to do in Postgres the equivalent of Pandas outer merge, in order to outer merge two tables. Table df_1 contains these data: Table df_2 contains these data: So Table df_1 has one extra column (random_id) than df_2. Also, job_id 1711418 and worker_id 45430 exist in both df_1 and df_2. If I use the &…

SQL: How do I find records that are within X days of one another?

Suppose I have a database called employees which looks like this: I want to return the employees that were hired within 2 days of one another. Here’s the closest that I’ve been able to get: The code above gives me the employees that were hired within 2 days of on another but only for their respect…

Count values between double quotes and brackets

How can I group by and count the values separated by double quotes between the brackets? I have 400K rows, so I’m also concerned about performance. Desired output: Answer Do you mean something like this? (The with clause is only for testing – remove it, and use your actual table and column names i…

SQL Snowflake Column Condition Check

Basically, I am trying to write a query against a table such like the following. Here we have Plans of either Free, Plus or Premium (in the example below I only show free and plus plans). Is it possible to return records where an ID that was original a ‘Free’ plan has changed to either a ‘pl…