I have a DataFrame called product_relationship_current and I’m doing a self-join to retrieve a new DataFrame like bellow: First I’m giving it an alias so I could consider them like two different dataframes: And then I’m doing a self-join to get a new dataframe: But I’m looking for another way to do that without doing a self-join, so I don’t
Tag: self-join
SQL – Returning all rows that are not ‘vice versa’ of one another
I’ve got a situation as follows (note this setup has been created as a minimal reproducible example). I have a table of houses, created like this: I have a large table called house_listings, like this: So, let’s say I run the following query: and I get the following output: and then I run the following query: select * from house_listings
SQL for identifying % of orders placed within 20 minutes of each other
Have a dataset like below and would like to know various ways to solve the question of : what % of orders were within 20 minutes of each other? CustomerId Order_# Order_Date 123 000112 12/25/2011 10:30 123 000113 12/25/2011 10:35 123 000114 12/25/2011 10:45 123 000115 12/25/2011 10:55 456 000113 12/25/2011 10:35 456 000113 1/25/2011 10:30 789 000117 9/25/2011 2:00
SQL SELF JOIN – driving me crazy
Can someone please tell me how to solve this question? And the thought process – like how do you think while solving this. It is driving me crazy. 🙁 Question – The attendance table logs the number of people counted in a crowd each day an event is held. Write a query to return a table showing the date and
Simple PostgreSQL Self Join
This is what my employee table looks like where manager_id is Foreign Key to the same table it references to employee_id and indicates which employee has manager and who is. I did self left join and the result was what was expected. But this query gives me So I don’t understand why it returns something instead of nothing.employee_id will never
PostgreSQL: Sub-Query on one table
My table looks (simplified) like this: It records filenames “File”; sometimes, a file (here BBB) is replaced by a newer one (here CCC”. First show all records, that have been replaced: OK, brings up line 2. Now I need to add a subquery column QQ, which shows the File of the substitute record, e.g. should bring: . My approach does
Convert multiple self JOINs to window function or subqueries (SQL)
I have a query with several self joins: Here is a sample table where in yellow I marked the record that is within the boundaries of the where condition: Here is the expected result view: Basically I filter one table with several consecutive conditions and show the result as a table. Is there a way, using window function or subquery
Understand the logical query processing when ‘Between’ condition is used in a self join of a SQL query
I have the following Orders table in PostgreSQL Database I need to return the cumulative sum of revenue for every order_date from last 2 days including the revenue for that order date. I am using the following query and it returns following result As per logical order of the query processing following steps will be performed The ‘JOIN’ will first
Efficient way to handle below query? in SQLServer or PostgreSql (Self join)
I have an employee table as below I need to select employee_id, manager_id, result. result should have true or false depends on below conditions. If the employee is manager for someone then true If the employee has a manager then true I came up with a query, but I need to know if there are any other better way to
JPA Criteria Builder query with inner SELECT statement
I need to create the below SQL join condition using JPA criteria builder, Below is the entity class and JPA query builder. I am able to build the query with join condition but cannot create the inner SELECT query. How can i create a inner select query for join clause? Requirement description: The below is the input table and output