I want to consolidate records based on a time gap of 5 minutes between the current row-end date and the next row start date. How can I achieve this T-SQL? Before Consolidation, the table is like below – It should look like below after consolidation – Answer This is a type of gaps-and-islands probl…
how to calculate the previous total with the current total with group by
I need to calculate every month with the previous months like: for each account. so how can I do it, I tried to extract the totals by each month but I didn’t get any result. DDLs: example of my data for the specified user is: this is the result that gives me: what I need now is: how to calculate
How to update table with summarized view from a config table?
I have a table A with data associated for an account for each month and there could be multiple entries in each month with following data as shown in snippet. Expected transformed table I want to generate table something like below as shown in below snippet. Idea is that for each distinct account_id in table …
Best practice for scaling SQL queries on joins?
I’m writing a REST api that works with SQL and am constantly finding myself in similar situations to this one, where I need to return lists of objects with nested lists inside each object by querying over table joins. Let’s say I have a many-to-many relationship between Users and Groups. I have a …
sql query for stratified sampling with dynamic sample size
Let say we have a table in this format: From this example, we see two stratas s1 and s2. What I want to do is stratified sampling and the sample size is the last column. For example, I want to randomly sample 2 instances from s1 and 1 random sample from s2. Any help is appreciated. Please keep in mind
Updating a table in SQL Server with information from another table
I have a “claims” table. Each claim has a client attached to it which is represented by a few letters “ABED”. For some reason, the actual clientID is nowhere to be found in the claims table so I want to fix this. The “Clients” table DOES contain both the code AND clientID. …
MYSQL subquery results columns not as expected
I am trying to build a query that will build a output like this. The output that I go is this I was following the instructions here https://www.mysqltutorial.org/mysql-subquery/ My query is this What I was expecting to happen was the alias ‘patient appt’ to be populated with the data from the nest…
Get Name from characters that died on Episode3 with its killer
I have a doubt on this sql problem. Here is the tables. I currenly have all the characters names that died on Episode 3, but I don’t know how to get the character killers. Any idea? Select name from …
Is it possible to pick data from SQL in a Lua code?
I’m coding with Solar2d in Lua and I wanted to pick data from an SQL table. Is it possible? Thank you
How to refactor my python to use a SQL Prepared statement?
Code to accept input from the user and gives a User for a given username. Now it is accepting the input directly into the SQL query but I would like to use it with prepared Statements, how could I do …