Viewing 15 posts - 16 through 30 (of 71 total)
Thanks Ken, for the confirmation that it cannot be done through windowing functions. This post is actually a follow-up to an earlier one I put up - Is loop necessary?...
October 25, 2021 at 8:13 am
You have the input in @T.
The output required is:
'2021-01-01', 100, null, 1
'2021-01-06', 125, 5.00, 1
'2021-01-08', 325, 100.0, 0
'2021-01-16', 155, 3.00, 1
I don't know how I can make it any clearer,...
October 24, 2021 at 6:05 pm
The first three rows output from my attempted query are what I expect.
The last row (2021-01-16) I want to be Usage = 3 and Result = 1. Currently, it is...
October 24, 2021 at 4:50 pm
The scenario is:
Result (Pass or Fail) is a function of Distance, where Distance = N - (N of previous latest Pass)
How can you work out Result for row N without...
October 10, 2021 at 12:52 pm
Many thanks to both of you!
I'd got bogged down in trying to use row_number and dense_rank, and didn't think about using lag.
October 5, 2021 at 3:03 pm
Thanks vliet. It is elegant but having to use a literal value in the windowing frame is a big limitation.
The islands method above also uses six windowing functions - two...
October 8, 2020 at 10:38 am
In my previous attempts, I don't think I can guarantee that RowGroup is unique across the two 'paths', and so could get incorrect result when combined. Would depend on the...
October 5, 2020 at 10:03 am
And without the UNION ALL.
declare @AtLeastCount int = 3
;with T as
(
select *,
RowNum0 = case when Val = 0 then row_number() over(order by ID) else null end,
RowNum1...
October 4, 2020 at 3:23 pm
My solution, no claim to originality.
declare @AtLeastCount int = 3
;with T as
(
select *, RowNum = row_number() over(order by ID)
from @T
),
T1 as
(
select *, RowGroup = RowNum - row_number()...
October 4, 2020 at 11:00 am
Thanks to all for the solutions!
On a quick look, sparked enough ideas for me to try and (hopefully) write a solution - don't want to be beaten by it. I...
October 2, 2020 at 5:08 pm
ZZartin thanks, that works. What if it was 'at least 4 1s' (would need new test data). Ideally the number would be variable, could that be achieved.
October 1, 2020 at 7:57 pm
The @R is just to get into a table what the result should be so that it can be easily read. It will play no part in any solution.
I did...
October 1, 2020 at 6:58 pm
select 'After', NULL, NULL
is not required in the result.
October 1, 2020 at 2:15 pm
Yes, I wasn't arguing for natural over surrogate keys, and tend to have both if possible. An ID for simplicity of joins and a unique index on other column(s). Hope...
August 23, 2020 at 8:04 pm
Viewing 15 posts - 16 through 30 (of 71 total)