Skip to content

Oracle – get previous, current and next year from query [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year. Improve this question Is below example good solution for get previous, current and next year?…

Flag “yes/No” if the subsequent row has same ID

I have data like this. If the same id is present in the next row, I want to flag as Yes. If it is not present then Make it as ‘No’. Can you kindly help me with the query? Thanks Answer The problem with multiple rows for the same ID and no other column that can be used to futher

sql prevent double booking with trigger

I am stumbled on constructing a DB table for hotel reservations. In my reservation db, there is a reservation start_datetime and end_datetime attribute to indicate booked period and I tried to prevent double booking with a trigger statemen, but I am certain that this method would be vulnerable to race conditi…

How do I get to choose MAX value by result of column?

I have this simple Table about chat Item I have my query that gets latest entered chat by chatId item as follow Now I would like to get latest item with isDone = 0 as priority. If any of result row has isDone = 0, it will get MAX(ID) with isDone = 0. If not, it will get the MAX(ID)

marked user with label by time for each month

Data source User ID Visit Date 1 2020-01-01 12:29:15 1 2020-01-02 12:30:11 1 2020-04-01 12:31:01 2 2020-05-01 12:31:14 Problem I need advice im trying to do sub query for this result to mark user as retention if they havent visit back for 3 month. i using this query for the data to get user’s latest vis…

Turn Cross Apply opensjson results into columns

We have a table that has a field with some json. using cross apply I was able to turn those pairs into columns: So how do I turn this into something like : Thanks. Answer If you know the limited set of possible key names in advance, you can just use PIVOT: But you can’t write a PIVOT if you