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
How to select a same column from a specialized table in PostgreSQL?
I have this table Person table is a general table which has these 2 specialization: I want to select data from physician and volunteer with the name of each person. Is there any possible way to do this? Let’s say I have this example data: Person: IDPerson Name P001 Andy P002 Rudy P003 Budy P004 Khal P00…
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
How to do a conditional statement in SQL where clause
What I’m trying to do is when @aValue parameter is like ‘abc%’ then run Otherwise if the @aValue param is not like ‘abc%’, then select all the records where the f.name is equal to @aValue. I’m trying to accomplish this using a CASE statement within my Where. In my where sta…
Is there a way to update ONLY field.type data onto SQL using dbWriteTable? Without having to pass the whole table’s value
So pretty much I am pulling a whole table from my database using: So this pulls my data as I need. After that perform some tests and to check the size of each column. I reassign field types based on my test. After that I would send the data back to the database using: Because I am not manipulating any
Second member of Azure AD group can not create schema in Azure SQL database
We have a curious issue with our Azure SQL database with AAD authentication. We have created a role (dbt_user) with all permissions, and excluded some schemas: Then, we add an AAD group (myAADGroup) as user, and add this to the role above: There are 2 members of the AAD group: user1@domain.com and user2@domai…