Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > DROP TABLE IF EXISTS dbo.Example; > > CREATE TABLE dbo.Example > ( > id integer PRIMARY KEY, > val integer NULL > ); > GO > > <pre> > ✓ > </pre> <!-- --> > INSERT dbo.Example > (id, val) > VALUES > (1, 136), > (2, NULL), > (3, 650), > (4, NULL), > (5, NULL), > (6, NULL), > (7, 954), > (8, NULL), > (9, 104), > (10, NULL); > GO > > <pre> 10 rows affected > </pre> <!-- --> > set statistics xml on; > SELECT > E.id, > E.val, > lastval = > CAST( > SUBSTRING( > MAX(CAST(E.id AS binary(4)) + CAST(E.val AS binary(4))) OVER ( > ORDER BY E.id > ROWS UNBOUNDED PRECEDING), > 5, 4) > AS integer) > FROM dbo.Example AS E > ORDER BY > E.id; > GO > > <pre> > id | val | lastval > -: | ---: | ------: > 1 | 136 | 136 > 2 | <em>null</em> | 136 > 3 | 650 | 650 > 4 | <em>null</em> | 650 > 5 | <em>null</em> | 650 > 6 | <em>null</em> | 650 > 7 | 954 | 954 > 8 | <em>null</em> | 954 > 9 | 104 | 104 > 10 | <em>null</em> | 104 > > | Microsoft SQL Server 2005 XML Showplan | > | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | > | &lt;ShowPlanXML xmlns=&quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&quot; Version=&quot;1.481&quot; Build=&quot;14.0.3045.24&quot;&gt;&lt;BatchSequence&gt;&lt;Batch&gt;&lt;Statements&gt;&lt;StmtSimple StatementText=&quot;SELECT&amp;#xd;&amp;#xa; E.id,&amp;#xd;&amp;#xa; E.val,&amp;#xd;&amp;#xa; lastval =&amp;#xd;&amp;#xa; CAST(&amp;#xd;&amp;#xa; SUBSTRING(&amp;#xd;&amp;#xa; MAX(CAST(E.id AS binary(4)) + CAST(E.val AS binary(4))) OVER (&amp;#xd;&amp;#xa; ORDER BY E.id&amp;#xd;&amp;#xa; ROWS UNBOUNDED PRECEDING),&amp;#xd;&amp;#xa; 5, 4)&amp;#xd;&amp;#xa; AS integer)&amp;#xd;&amp;#xa;FROM dbo.Example AS E&amp;#xd;&amp;#xa;ORDER BY&amp;#xd;&amp;#xa; E.id&quot; StatementId=&quot;1&quot; StatementCompId=&quot;2&quot; StatementType=&quot;SELECT&quot; RetrievedFromCache=&quot;true&quot; StatementSubTreeCost=&quot;0.0033274&quot; StatementEstRows=&quot;10&quot; SecurityPolicyApplied=&quot;false&quot; StatementOptmLevel=&quot;TRIVIAL&quot; QueryHash=&quot;0x298EB991F7DFB3FD&quot; QueryPlanHash=&quot;0xC11B8E49EAA78CF9&quot; CardinalityEstimationModelVersion=&quot;140&quot;&gt;&lt;StatementSetOptions QUOTED_IDENTIFIER=&quot;true&quot; ARITHABORT=&quot;true&quot; CONCAT_NULL_YIELDS_NULL=&quot;true&quot; ANSI_NULLS=&quot;true&quot; ANSI_PADDING=&quot;true&quot; ANSI_WARNINGS=&quot;true&quot; NUMERIC_ROUNDABORT=&quot;false&quot;&gt;&lt;/StatementSetOptions&gt;&lt;QueryPlan DegreeOfParallelism=&quot;0&quot; NonParallelPlanReason=&quot;NoParallelPlansInDesktopOrExpressEdition&quot; CachedPlanSize=&quot;40&quot; CompileTime=&quot;0&quot; CompileCPU=&quot;0&quot; CompileMemory=&quot;184&quot;&gt;&lt;Warnings&gt;&lt;PlanAffectingConvert ConvertIssue=&quot;Cardinality Estimate&quot; Expression=&quot;CONVERT(binary(4),[E].[id],0)&quot;&gt;&lt;/PlanAffectingConvert&gt;&lt;PlanAffectingConvert ConvertIssue=&quot;Cardinality Estimate&quot; Expression=&quot;CONVERT(binary(4),[E].[val],0)&quot;&gt;&lt;/PlanAffectingConvert&gt;&lt;/Warnings&gt;&lt;MemoryGrantInfo SerialRequiredMemory=&quot;0&quot; SerialDesiredMemory=&quot;0&quot;&gt;&lt;/MemoryGrantInfo&gt;&lt;OptimizerHardwareDependentProperties EstimatedAvailableMemoryGrant=&quot;419378&quot; EstimatedPagesCached=&quot;26211&quot; EstimatedAvailableDegreeOfParallelism=&quot;1&quot; MaxCompileMemory=&quot;882128&quot;&gt;&lt;/OptimizerHardwareDependentProperties&gt;&lt;TraceFlags IsCompileTime=&quot;1&quot;&gt;&lt;TraceFlag Value=&quot;460&quot; Scope=&quot;Global&quot;&gt;&lt;/TraceFlag&gt;&lt;TraceFlag Value=&quot;8017&quot; Scope=&quot;Global&quot;&gt;&lt;/TraceFlag&gt;&lt;/TraceFlags&gt;&lt;TraceFlags IsCompileTime=&quot;0&quot;&gt;&lt;TraceFlag Value=&quot;460&quot; Scope=&quot;Global&quot;&gt;&lt;/TraceFlag&gt;&lt;TraceFlag Value=&quot;8017&quot; Scope=&quot;Global&quot;&gt;&lt;/TraceFlag&gt;&lt;/TraceFlags&gt;&lt;QueryTimeStats ElapsedTime=&quot;0&quot; CpuTime=&quot;0&quot;&gt;&lt;/QueryTimeStats&gt;&lt;RelOp NodeId=&quot;0&quot; PhysicalOp=&quot;Compute Scalar&quot; LogicalOp=&quot;Compute Scalar&quot; EstimateRows=&quot;10&quot; EstimateIO=&quot;0&quot; EstimateCPU=&quot;1e-006&quot; AvgRowSize=&quot;19&quot; EstimatedTotalSubtreeCost=&quot;0.0033274&quot; Parallel=&quot;0&quot; EstimateRebinds=&quot;0&quot; EstimateRewinds=&quot;0&quot; EstimatedExecutionMode=&quot;Row&quot;&gt;&lt;OutputList&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Expr1003&quot;&gt;&lt;/ColumnReference&gt;&lt;/OutputList&gt;&lt;ComputeScalar&gt;&lt;DefinedValues&gt;&lt;DefinedValue&gt;&lt;ColumnReference Column=&quot;Expr1003&quot;&gt;&lt;/ColumnReference&gt;&lt;ScalarOperator ScalarString=&quot;CONVERT(int,substring([Expr1002],(5),(4)),0)&quot;&gt;&lt;Convert DataType=&quot;int&quot; Style=&quot;0&quot; Implicit=&quot;0&quot;&gt;&lt;ScalarOperator&gt;&lt;Intrinsic FunctionName=&quot;substring&quot;&gt;&lt;ScalarOperator&gt;&lt;Identifier&gt;&lt;ColumnReference Column=&quot;Expr1002&quot;&gt;&lt;/ColumnReference&gt;&lt;/Identifier&gt;&lt;/ScalarOperator&gt;&lt;ScalarOperator&gt;&lt;Const ConstValue=&quot;(5)&quot;&gt;&lt;/Const&gt;&lt;/ScalarOperator&gt;&lt;ScalarOperator&gt;&lt;Const ConstValue=&quot;(4)&quot;&gt;&lt;/Const&gt;&lt;/ScalarOperator&gt;&lt;/Intrinsic&gt;&lt;/ScalarOperator&gt;&lt;/Convert&gt;&lt;/ScalarOperator&gt;&lt;/DefinedValue&gt;&lt;/DefinedValues&gt;&lt;RelOp NodeId=&quot;1&quot; PhysicalOp=&quot;Stream Aggregate&quot; LogicalOp=&quot;Aggregate&quot; EstimateRows=&quot;10&quot; EstimateIO=&quot;0&quot; EstimateCPU=&quot;6.28e-006&quot; AvgRowSize=&quot;39&quot; EstimatedTotalSubtreeCost=&quot;0.0033264&quot; Parallel=&quot;0&quot; EstimateRebinds=&quot;0&quot; EstimateRewinds=&quot;0&quot; EstimatedExecutionMode=&quot;Row&quot;&gt;&lt;OutputList&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Expr1002&quot;&gt;&lt;/ColumnReference&gt;&lt;/OutputList&gt;&lt;RunTimeInformation&gt;&lt;RunTimeCountersPerThread Thread=&quot;0&quot; ActualRows=&quot;10&quot; Batches=&quot;0&quot; ActualExecutionMode=&quot;Row&quot; ActualElapsedms=&quot;0&quot; ActualCPUms=&quot;0&quot; ActualEndOfScans=&quot;1&quot; ActualExecutions=&quot;1&quot;&gt;&lt;/RunTimeCountersPerThread&gt;&lt;/RunTimeInformation&gt;&lt;StreamAggregate&gt;&lt;DefinedValues&gt;&lt;DefinedValue&gt;&lt;ColumnReference Column=&quot;Expr1002&quot;&gt;&lt;/ColumnReference&gt;&lt;ScalarOperator ScalarString=&quot;MAX([Expr1004])&quot;&gt;&lt;Aggregate Distinct=&quot;0&quot; AggType=&quot;MAX&quot;&gt;&lt;ScalarOperator&gt;&lt;Identifier&gt;&lt;ColumnReference Column=&quot;Expr1004&quot;&gt;&lt;/ColumnReference&gt;&lt;/Identifier&gt;&lt;/ScalarOperator&gt;&lt;/Aggregate&gt;&lt;/ScalarOperator&gt;&lt;/DefinedValue&gt;&lt;DefinedValue&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ScalarOperator ScalarString=&quot;ANY([fiddle_7b4d9e0e85724f7e816ad79ca84b333a].[dbo].[Example].[id] as [E].[id])&quot;&gt;&lt;Aggregate Distinct=&quot;0&quot; AggType=&quot;ANY&quot;&gt;&lt;ScalarOperator&gt;&lt;Identifier&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;/Identifier&gt;&lt;/ScalarOperator&gt;&lt;/Aggregate&gt;&lt;/ScalarOperator&gt;&lt;/DefinedValue&gt;&lt;DefinedValue&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;ScalarOperator ScalarString=&quot;ANY([fiddle_7b4d9e0e85724f7e816ad79ca84b333a].[dbo].[Example].[val] as [E].[val])&quot;&gt;&lt;Aggregate Distinct=&quot;0&quot; AggType=&quot;ANY&quot;&gt;&lt;ScalarOperator&gt;&lt;Identifier&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;/Identifier&gt;&lt;/ScalarOperator&gt;&lt;/Aggregate&gt;&lt;/ScalarOperator&gt;&lt;/DefinedValue&gt;&lt;/DefinedValues&gt;&lt;GroupBy&gt;&lt;ColumnReference Column=&quot;WindowCount1008&quot;&gt;&lt;/ColumnReference&gt;&lt;/GroupBy&gt;&lt;RelOp NodeId=&quot;2&quot; PhysicalOp=&quot;Window Spool&quot; LogicalOp=&quot;Window Spool&quot; EstimateRows=&quot;20&quot; EstimateIO=&quot;0&quot; EstimateCPU=&quot;2.198e-005&quot; AvgRowSize=&quot;39&quot; EstimatedTotalSubtreeCost=&quot;0.00332012&quot; Parallel=&quot;0&quot; EstimateRebinds=&quot;0&quot; EstimateRewinds=&quot;0&quot; EstimatedExecutionMode=&quot;Row&quot;&gt;&lt;OutputList&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Expr1004&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;RowNumber1005&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;WindowCount1008&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Segment1007&quot;&gt;&lt;/ColumnReference&gt;&lt;/OutputList&gt;&lt;RunTimeInformation&gt;&lt;RunTimeCountersPerThread Thread=&quot;0&quot; ActualRows=&quot;20&quot; Batches=&quot;0&quot; ActualExecutionMode=&quot;Row&quot; ActualElapsedms=&quot;0&quot; ActualCPUms=&quot;0&quot; ActualEndOfScans=&quot;1&quot; ActualExecutions=&quot;1&quot;&gt;&lt;/RunTimeCountersPerThread&gt;&lt;/RunTimeInformation&gt;&lt;WindowSpool&gt;&lt;RelOp NodeId=&quot;3&quot; PhysicalOp=&quot;Segment&quot; LogicalOp=&quot;Segment&quot; EstimateRows=&quot;10&quot; EstimateIO=&quot;0&quot; EstimateCPU=&quot;6.28e-007&quot; AvgRowSize=&quot;39&quot; EstimatedTotalSubtreeCost=&quot;0.00329563&quot; Parallel=&quot;0&quot; EstimateRebinds=&quot;0&quot; EstimateRewinds=&quot;0&quot; EstimatedExecutionMode=&quot;Row&quot;&gt;&lt;OutputList&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Expr1004&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;RowNumber1005&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Segment1007&quot;&gt;&lt;/ColumnReference&gt;&lt;/OutputList&gt;&lt;RunTimeInformation&gt;&lt;RunTimeCountersPerThread Thread=&quot;0&quot; ActualRows=&quot;10&quot; Batches=&quot;0&quot; ActualExecutionMode=&quot;Row&quot; ActualElapsedms=&quot;0&quot; ActualCPUms=&quot;0&quot; ActualEndOfScans=&quot;1&quot; ActualExecutions=&quot;1&quot;&gt;&lt;/RunTimeCountersPerThread&gt;&lt;/RunTimeInformation&gt;&lt;Segment&gt;&lt;GroupBy&gt;&lt;/GroupBy&gt;&lt;SegmentColumn&gt;&lt;ColumnReference Column=&quot;Segment1007&quot;&gt;&lt;/ColumnReference&gt;&lt;/SegmentColumn&gt;&lt;RelOp NodeId=&quot;4&quot; PhysicalOp=&quot;Sequence Project&quot; LogicalOp=&quot;Compute Scalar&quot; EstimateRows=&quot;10&quot; EstimateIO=&quot;0&quot; EstimateCPU=&quot;8e-007&quot; AvgRowSize=&quot;31&quot; EstimatedTotalSubtreeCost=&quot;0.003295&quot; Parallel=&quot;0&quot; EstimateRebinds=&quot;0&quot; EstimateRewinds=&quot;0&quot; EstimatedExecutionMode=&quot;Row&quot;&gt;&lt;OutputList&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Expr1004&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;RowNumber1005&quot;&gt;&lt;/ColumnReference&gt;&lt;/OutputList&gt;&lt;RunTimeInformation&gt;&lt;RunTimeCountersPerThread Thread=&quot;0&quot; ActualRows=&quot;10&quot; Batches=&quot;0&quot; ActualExecutionMode=&quot;Row&quot; ActualElapsedms=&quot;0&quot; ActualCPUms=&quot;0&quot; ActualEndOfScans=&quot;1&quot; ActualExecutions=&quot;1&quot;&gt;&lt;/RunTimeCountersPerThread&gt;&lt;/RunTimeInformation&gt;&lt;SequenceProject&gt;&lt;DefinedValues&gt;&lt;DefinedValue&gt;&lt;ColumnReference Column=&quot;RowNumber1005&quot;&gt;&lt;/ColumnReference&gt;&lt;ScalarOperator ScalarString=&quot;row_number&quot;&gt;&lt;Sequence FunctionName=&quot;row_number&quot;&gt;&lt;/Sequence&gt;&lt;/ScalarOperator&gt;&lt;/DefinedValue&gt;&lt;/DefinedValues&gt;&lt;RelOp NodeId=&quot;5&quot; PhysicalOp=&quot;Segment&quot; LogicalOp=&quot;Segment&quot; EstimateRows=&quot;10&quot; EstimateIO=&quot;0&quot; EstimateCPU=&quot;2e-007&quot; AvgRowSize=&quot;31&quot; EstimatedTotalSubtreeCost=&quot;0.0032942&quot; Parallel=&quot;0&quot; EstimateRebinds=&quot;0&quot; EstimateRewinds=&quot;0&quot; EstimatedExecutionMode=&quot;Row&quot;&gt;&lt;OutputList&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Expr1004&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Segment1006&quot;&gt;&lt;/ColumnReference&gt;&lt;/OutputList&gt;&lt;RunTimeInformation&gt;&lt;RunTimeCountersPerThread Thread=&quot;0&quot; ActualRows=&quot;10&quot; Batches=&quot;0&quot; ActualExecutionMode=&quot;Row&quot; ActualElapsedms=&quot;0&quot; ActualCPUms=&quot;0&quot; ActualEndOfScans=&quot;1&quot; ActualExecutions=&quot;1&quot;&gt;&lt;/RunTimeCountersPerThread&gt;&lt;/RunTimeInformation&gt;&lt;Segment&gt;&lt;GroupBy&gt;&lt;/GroupBy&gt;&lt;SegmentColumn&gt;&lt;ColumnReference Column=&quot;Segment1006&quot;&gt;&lt;/ColumnReference&gt;&lt;/SegmentColumn&gt;&lt;RelOp NodeId=&quot;6&quot; PhysicalOp=&quot;Compute Scalar&quot; LogicalOp=&quot;Compute Scalar&quot; EstimateRows=&quot;10&quot; EstimateIO=&quot;0&quot; EstimateCPU=&quot;1e-006&quot; AvgRowSize=&quot;23&quot; EstimatedTotalSubtreeCost=&quot;0.003294&quot; Parallel=&quot;0&quot; EstimateRebinds=&quot;0&quot; EstimateRewinds=&quot;0&quot; EstimatedExecutionMode=&quot;Row&quot;&gt;&lt;OutputList&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Column=&quot;Expr1004&quot;&gt;&lt;/ColumnReference&gt;&lt;/OutputList&gt;&lt;ComputeScalar&gt;&lt;DefinedValues&gt;&lt;DefinedValue&gt;&lt;ColumnReference Column=&quot;Expr1004&quot;&gt;&lt;/ColumnReference&gt;&lt;ScalarOperator ScalarString=&quot;CONVERT(binary(4),[fiddle_7b4d9e0e85724f7e816ad79ca84b333a].[dbo].[Example].[id] as [E].[id],0)+CONVERT(binary(4),[fiddle_7b4d9e0e85724f7e816ad79ca84b333a].[dbo].[Example].[val] as [E].[val],0)&quot;&gt;&lt;Arithmetic Operation=&quot;ADD&quot;&gt;&lt;ScalarOperator&gt;&lt;Convert DataType=&quot;binary&quot; Length=&quot;4&quot; Style=&quot;0&quot; Implicit=&quot;0&quot;&gt;&lt;ScalarOperator&gt;&lt;Identifier&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;/Identifier&gt;&lt;/ScalarOperator&gt;&lt;/Convert&gt;&lt;/ScalarOperator&gt;&lt;ScalarOperator&gt;&lt;Convert DataType=&quot;binary&quot; Length=&quot;4&quot; Style=&quot;0&quot; Implicit=&quot;0&quot;&gt;&lt;ScalarOperator&gt;&lt;Identifier&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;/Identifier&gt;&lt;/ScalarOperator&gt;&lt;/Convert&gt;&lt;/ScalarOperator&gt;&lt;/Arithmetic&gt;&lt;/ScalarOperator&gt;&lt;/DefinedValue&gt;&lt;/DefinedValues&gt;&lt;RelOp NodeId=&quot;7&quot; PhysicalOp=&quot;Clustered Index Scan&quot; LogicalOp=&quot;Clustered Index Scan&quot; EstimateRows=&quot;10&quot; EstimatedRowsRead=&quot;10&quot; EstimateIO=&quot;0.003125&quot; EstimateCPU=&quot;0.000168&quot; AvgRowSize=&quot;15&quot; EstimatedTotalSubtreeCost=&quot;0.003293&quot; TableCardinality=&quot;10&quot; Parallel=&quot;0&quot; EstimateRebinds=&quot;0&quot; EstimateRewinds=&quot;0&quot; EstimatedExecutionMode=&quot;Row&quot;&gt;&lt;OutputList&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;/OutputList&gt;&lt;RunTimeInformation&gt;&lt;RunTimeCountersPerThread Thread=&quot;0&quot; ActualRows=&quot;10&quot; Batches=&quot;0&quot; ActualExecutionMode=&quot;Row&quot; ActualElapsedms=&quot;0&quot; ActualCPUms=&quot;0&quot; ActualScans=&quot;1&quot; ActualLogicalReads=&quot;2&quot; ActualPhysicalReads=&quot;0&quot; ActualReadAheads=&quot;0&quot; ActualLobLogicalReads=&quot;0&quot; ActualLobPhysicalReads=&quot;0&quot; ActualLobReadAheads=&quot;0&quot; ActualRowsRead=&quot;10&quot; ActualEndOfScans=&quot;1&quot; ActualExecutions=&quot;1&quot;&gt;&lt;/RunTimeCountersPerThread&gt;&lt;/RunTimeInformation&gt;&lt;IndexScan Ordered=&quot;1&quot; ScanDirection=&quot;FORWARD&quot; ForcedIndex=&quot;0&quot; ForceSeek=&quot;0&quot; ForceScan=&quot;0&quot; NoExpandHint=&quot;0&quot; Storage=&quot;RowStore&quot;&gt;&lt;DefinedValues&gt;&lt;DefinedValue&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;id&quot;&gt;&lt;/ColumnReference&gt;&lt;/DefinedValue&gt;&lt;DefinedValue&gt;&lt;ColumnReference Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Alias=&quot;[E]&quot; Column=&quot;val&quot;&gt;&lt;/ColumnReference&gt;&lt;/DefinedValue&gt;&lt;/DefinedValues&gt;&lt;Object Database=&quot;[fiddle_7b4d9e0e85724f7e816ad79ca84b333a]&quot; Schema=&quot;[dbo]&quot; Table=&quot;[Example]&quot; Index=&quot;[PK__Example__3213E83F536B8870]&quot; Alias=&quot;[E]&quot; IndexKind=&quot;Clustered&quot; Storage=&quot;RowStore&quot;&gt;&lt;/Object&gt;&lt;/IndexScan&gt;&lt;/RelOp&gt;&lt;/ComputeScalar&gt;&lt;/RelOp&gt;&lt;/Segment&gt;&lt;/RelOp&gt;&lt;/SequenceProject&gt;&lt;/RelOp&gt;&lt;/Segment&gt;&lt;/RelOp&gt;&lt;/WindowSpool&gt;&lt;/RelOp&gt;&lt;/StreamAggregate&gt;&lt;/RelOp&gt;&lt;/ComputeScalar&gt;&lt;/RelOp&gt;&lt;/QueryPlan&gt;&lt;/StmtSimple&gt;&lt;/Statements&gt;&lt;/Batch&gt;&lt;/BatchSequence&gt;&lt;/ShowPlanXML&gt; | > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=a7225c9927ea0477a95c5e1696abd228)*
back to fiddle