Skip to content

Scenarios andsSteps “get last change” problem

I have following table abstracting some scenarios and their steps ordered by START_DATE “desc”. SCENARIO_KEY STEP_KEY START_DATE END_DATE PREVIOUS_SCENARIO_KEY PREVIOUS_STEP_KEY 128 44 20xx04x4 0 120 44 120 44 20xx03x3 20xx04x4 120 38 120 38 20xx11x0 20xx03x3 121 38 121 38 20xx07x2 20xx11x0 120 44…

How to return deleted rows using jdbi?

How do I return the deleted rows using jdbi? For example, I’d like to do something like this: Answer Postgresql has a returning keyword… https://dbfiddle.uk/?rdbms=postgres_13&fiddle=25d284309745e40c8ea29945481d1aa2 You can then execute that query in the same way as you would a normal SELECT s…

Grouping by a Range of Numbers with Aggregate Function

I have data in Hive that has two columns of interest. The first is a column (int) that represents a date (YYYYMM) and the second is a column (int) that represents a number of people for that date. I’m trying to write a query that sums up the number of people for comparison across two quarters. For examp…

Track state of time series event in SQL column

This seems really simple but I can’t figure it out, working in SQL Server. I have time series data and I want a column to track the state of ON/OFF events for each row, so when there’s an ON event then the Desired Output column will have a 1 for each subsequent event until there is an OFF event. P…

Oracle Sql- Adding column to pivot result

I’m have an issue that I’m not entirely sure how to fix. So I have a table of the format Where order_type is the column in question I use to pivot. Value is the column I’m using to run aggregates, but the problem is Units. So for each unique ID + order_type combo, units will be the same. But…