What I’m trying to do is take a record that looks like this: and change it to look like this: it can be done in Python but I am not sure if it is possible with SQL Oracle? I am having difficult time making this work. Any help would be appreciated. Thanks Answer connect by level is useful for these
Tag: recursive-query
How to unnest the table based on date interval in Presto?
I have a table with events, where start_dt is a start and end_dt an end of the event. This table is partitioned by dt column derived from the end_dt. This means that events that start before and end after midnight are present only in one partition. What I need to do is to split each event into as many rows
SQL Flag Rows Occurring 2 Hours After Previous Flag
I have some messy RFID data due to over sensitive antenna’s. There is a physical process that tracks an RFID tag moving through different stations in a cycle. An item with an RFID tag can move through the cycle more than one time a day, but it is highly unlikely that it could start the cycle within a two hour
Find ALL the prerequisites for a given course
I have the following tables: COURSE_PREREQUISITES My question is: How can I obtain all the course ids a student needs to take before he can take course id 6? Intended Answer: I should obtain the course id of 1, 2, 3, 4, 5. Attempts Made: I have tried selecting the prerequisite_course_id of the intended final course id 6, and nesting
Grouping shift data by 7-day windows in SQL Server 2012
What I want to do is to calculate the number of shifts and hours worked by each employee in any given 7-day period. In order to achieve this, I need to identify and group ‘islands’ of shifts. Note …
How to exclude weekends and holidays dates and find an expected date in MySQL?
I am working on a task where I have 2 tables. i.e, tickets and holidays. Now I also have the number of days to complete the tickets. Now I need to find the expected date by excluding holidays(specified in the holidays table) and weekends. Now I can able to find a date using ticket created date and days to complete
MySQL – select distinct values from a column where values are separated by comma
To get the list of distinct values from table1 and column1 is as easy as doing this: However, I inherited (unfortunately) a database where column1 contains values separated by a comma I need to get the list of distinct values from column1, so it looks like this: Any ideas? Answer A generic method uses a recursive query (available in MySQL
select linked rows in the same table
I’m creating a branching dialog game, and used a dialog tool that outputs JSON with a link and a link_path to connect dialogs together. I’ve parsed and inserted this structure in PostgreSQL. I want to …
Calculate the time taken by a recursive function each time it is called… in SQL
I have the data like below id | Function_name | event | time 1 function_a start 12:01 2 function_a start 12:02 3 function_a start 12:03 4 function_a end 12:04 …
Partitioning rows into groups by accumulative time interval
I got a search sessions log that looks like this: My task is to partition each row into session groups. Session groups are up to five minutes. For example: Those TOP 3 sessions will form a group session 1 – if we accumulate the minutes between each row, we will get 3 minutes and the 4th would accumulate to more