All Questions
12 questions
0
votes
1
answer
60
views
How can I generate recursive rows for my table using LAG?
Sample data and current attempt: https://dbfiddle.uk/A6zVd_Qy
I've got a table that looks like this:
CREATE TABLE base_table
(
FUND_CODE varchar(255),
OPENING_BALANCE float,
TRANSACTION_DATE ...
0
votes
2
answers
121
views
Grouping rows by fixed integer window that resets above a threshold
I am trying to group rows together using a counter of elapsed days from the previous row. These groups would represent a period of 180 elapsed days and no more. If a new row would break this rule (i.e....
2
votes
3
answers
90
views
Recursive query to use a date returned in initial query as limit in subsequent query
I have a business need to project when a specific task needs to be done based on the usage of a task.
For example, you need to change the oil in your car every 3000 miles. Some days you drive 300 ...
0
votes
1
answer
37
views
Select results based on nearest date window
I have a SQL Server table as follows. I would like to group by name and place of test taken, order by date ascending as partition based on above mentioned grouping.
now a configurable window of eg:4 ...
1
vote
1
answer
270
views
Partitioning rows into groups by accumulative time interval
I got a search sessions log that looks like this:
+----------+-------------------------+----------+
| dt | search_time | searches |
+----------+-------------------------+----------+
|...
3
votes
2
answers
111
views
T-SQL sequential updating with two columns
I have a table created by:
CREATE TABLE table1
(
id INT,
multiplier INT,
col1 DECIMAL(10,5)
)
INSERT INTO table1
VALUES (1, 2, 1.53), (2, 3, NULL), (3, 2, NULL),
(4, 2, NULL), (5,...
-1
votes
2
answers
129
views
SQL question - how to output using iterative date logic in SQL Server
I have the following sample table (provided with single ID for simplicity - need to perform the same logic across all IDs)
ID Visit_date
-----------------
ABC 8/7/2019
ABC 9/10/2019
ABC 9/12/...
1
vote
1
answer
59
views
Generate the SQL row numbers based on the 10 days filters
Customer_Id Call_Date Agent_M_Code Row_Indicator
810471698 2020-03-19 13:25:24.910 rmanzan2 1
810471698 2020-03-22 20:28:19.067 pmaclair 2
...
1
vote
2
answers
62
views
How to capture first row in a grouping and subsequent rows that are each a minimum of 15 days apart?
Assume a given insurance will only pay for the same patient visiting the same doctor once in 15 days. If the patient comes once, twice, or twenty times within those 15 days to the doctor, the doctor ...
1
vote
1
answer
66
views
Combine all previous columns to the current column
I have a table called terms and I am using SQL Server 2014
termID termname
1 term1
2 term2
3 term3
4 term4
I would like to have the result like this
termID ...
0
votes
1
answer
54
views
Unexpected data at typical recursion
It's hard for me to use words to describe this, so here's the sample:
select *
into t
from (values (10, 'A'),
(25, 'B'),
(30, 'C'),
(45, 'D'),
(52, ...
1
vote
1
answer
271
views
Interpolate missing values when joining two tables
I have two tables of different density data and I'd like to be able to join them but interpolate this values in the lower frequency table to fill in the gaps.
I have no idea how to approach this ...