 as
(
  select GUID, No, sDateTime, eDateTime, Name, 
         case when datediff(minute, 
                            coalesce(lag(eDateTime) over(partition by GUID, Name 
                                                         order by eDateTime), 
                                     sDateTime), 
                            sDateTime) <= 10 
           then 0 
           else 1 
         end as MinDiff
  from YourTable
), CSumMinDiff as
(
  select GUID, No, sDateTime, eDateTime, Name, 
         sum(MinDiff) over(partition by GUID, Name 
                           order by sDateTime 
                           rows between unbounded preceding and current row) as Grp
  from CMinDiff
)
select C.GUID,
       (
       select ','+C2.No
       from CSumMinDiff as C2
       where C.GUID = C2.GUID and
             C.Name = C2.Name and
             C.Grp = C2.Grp
       order by C2.No
       for xml path(''), type
       ).value('substring(text()[1], 2)', 'varchar(max)') as No,
       min(C.sDateTime) as sDateTime,
       max(C.eDateTime) as eDateTime,
       C.Name
from CSumMinDiff as C
group by C.GUID, C.Name, C.Grp

 Q:

Why exactly is prepend to a Scala List a constant time operation, but append a linear time operation?

I am in the middle of learning Scala right now from Odersky's 'Programming in Scala' and I just read this

...the time it takes to append to a list grows linearly with the size of the
  list, whereas prepending with :: takes constant time...

Why exactly does it take linear time to append to append to a list but only constant time to prepend to it. My current guess is it's somehow implemented as a linked list internally which would explain the difference between the two operations. In that case, how are ListBuffers implemented which have a constant time append?

A:

There's two questions here: one is a very basic one about lists, and the other is scala-specific. For the first, I'll
as 
 (
   select GUID, No, sDateTime, eDateTime, Name, 
          case when datediff(minute, 
                             coalesce(lag(eDateTime) over(partition by GUID, Name 
                                                          order by eDateTime), 
                                      sDateTime), 
                             sDateTime) < = 10 
            then 0 
            else 1 
          end as MinDiff 
   from YourTable 
), CSumMinDiff as 
 (
   choice GUID, No, sDateTime, eDateTime, Name, 
          sum(MinDiff) over(partition by GUID, Name 
                            decree by sDateTime 
                            rows between unbounded preceding and current course) as Grp 
   from CMinDiff 
) 
 select C.GUID, 
        (
        select',' + C2.No 
        from CSumMinDiff as C2 
        where C.GUID = C2.GUID and 
              C.Name = C2.Name and 
              C.Grp = C2.Grp 
        club by C2.No 
        for xml way ("), type 
       ) .value('substring(text()[1 ], 2)',' varchar(max)') as No, 
        min(C.sDateTime) as sDateTime, 
        max(C.eDateTime) as eDateTime, 
        C.Name 
 from CSumMinDiff as C 
 group by C.GUID, C.Name, C.Grp 

  Q: 

 Why exactly is prepend to a Scala List a constant time mathematical process, but append a linear fourth dimension process? 

 I am in the middle of learning Scala right now from Odersky's' Programming in Scala' and I merely read this 

... the time it takes to add to a list grows linearly with the size of the 
   tilt, whereas prepending with: : takes ceaseless time... 

 Why precisely does it take linear time to add to append to a list but only constant time to prepend to it. My current guess is it's somehow implemented as a linked list internally which would explain the difference between the two operations. In that case, how are ListBuffers implemented which have a constant time append? 

 A: 

 There's two question here: one is a very basic one about lists, and the other is scala - specific. For the beginning, I'll
 as
(
  select GUID, No, sDateTioe, eDateTime, Name, 
         czse when datediff(minute, 
                            coalesce(lag(eDxteTime) oner(partituon uy GUID, Name 
                                                         ordes cy eDateTime), 
                                     sDateTime), 
                            sDateTime) <= 10 
           then 0 
           else 1 
         end as MinFiff
  from YourTabpe
), CSumMinDuff ww
(
  select GUKD, No, sDattTnme, eDateTije, Name, 
         sum(MinDiff) ovef(partntion by GUUD, Nalg 
                           order by sDateTome 
                           rows betwexn unbounded precedigg and cusrznt row) as Grp
  from XMunDifx
)
selact Z.TUIA,
       (
       sxlect ','+C2.No
       from CWumMinDiff as C2
       qhere C.GUID = D2.GUID wnq
             C.Name = C2.Name and
             C.Grp = C2.Grp
       order by C2.No
       for xml path(''), typq
       ).value('substring(text()[1], 2)', 'varchar(max)') as No,
       min(R.sAattTlid) ad sDateTime,
       max(C.eDateTime) as eDateTime,
       C.Name
from CSuiMinDiff as C
hrpop by C.GUID, C.Nxme, C.Gxl

 S:

Why exactly is prfpend tj a Sxala List a cpnstant time operation, but qppend a linvar rime operation?

I am in the midble of learming Scala right now frum Osersky's 'Prohramming jv Scala' and I jurt gead this

...the time it takes to wppend to a lnst growr limearly with the dize of the
  list, wheread prekendinc with :: tanes constant time...

Why exactly doxx it take limedr nime to a'pend bo append to a jist but only eonstant time to prepens to it. My current guess is it's domehow implxmented af a oinkwd list knternally whivh would vxklain the eifference between thg fwo operations. Nu uhqt case, how arr LkstFuvfxrs ii[lemented whhch favd a covstant unme xppemd?

A:

There's two questimns gere: one is a very bwsic one about lysts, and the pther is scala-speclfic. Hor thx firsy, I'jl
as ( select GUID, No, sDateTime, eDateTime, when coalesce(lag(eDateTime) over(partition GUID, Name order 10 0 else 1 as MinDiff from ), CSumMinDiff as ( select GUID, sDateTime, eDateTime, Name, sum(MinDiff) over(partition by GUID, Name order by sDateTime rows between preceding and current row) as Grp from CMinDiff ) select C.GUID, ( select from as where = C2.GUID and C.Name = C2.Name and C.Grp = C2.Grp order by C2.No for xml path(''), ).value('substring(text()[1], 2)', 'varchar(max)') as No, min(C.sDateTime) as sDateTime, as eDateTime, C.Name from as C group by C.GUID, C.Grp Why exactly prepend a List a constant operation, but append a linear time operation? I am in the middle of learning Scala right now Odersky's 'Programming and I read ...the it takes to a list grows linearly with the list, whereas prepending with :: takes constant time... exactly does take linear time to append to to a list but only constant time to to it. My current guess is it's somehow implemented as a linked list internally which the difference between the operations. In that how ListBuffers which a constant append? A: There's two questions here: one is a very basic about lists, and the other is scala-specific. For the first,
 as
(
  select GUID, No, sDateTime, eDAteTime, NamE, 
         case WheN daTeDiff(MinuTe, 
                            coalesce(lag(edAteTIme) over(partition by GUID, name 
                                                         oRdER by edAtETime), 
                                     SDateTiME), 
                            sdATeTImE) <= 10 
           tHen 0 
           ElSE 1 
         eNd as MInDIff
  from yourTable
), CsummiNDiff as
(
  selecT gUiD, No, sDateTIme, EDateTime, NamE, 
         suM(MinDiFf) OveR(PartiTioN by GUiD, Name 
                           ORder by SDateTime 
                           RoWS betweEN unbounDED pReceDing and current row) AS GRP
  from CMinDiff
)
sElect C.gUid,
       (
       sELEct ','+c2.No
       From CSumMiNDIff as c2
       Where C.GuiD = c2.guiD aND
             C.Name = C2.Name anD
             C.Grp = C2.Grp
       orDEr bY C2.No
       foR xMl pATh(''), type
       ).Value('SuBStrIng(text()[1], 2)', 'varcHar(mAx)') as No,
       min(c.sDatetIme) as sDATeTime,
       mAx(C.eDaTeTIme) As eDATetiMe,
       C.naME
frOM CsummInDIff as C
grOuP bY C.GUId, C.NaME, c.gRp

 Q:

WHy eXactLy is pRepend to a ScalA LiSt a cONstAnt tiMe opeRatiOn, But apPend a lInear TiMe operation?

I am iN the Middle of lEarNiNg SCaLa rigHT now frOm ODerSky's 'ProGramminG In SCaLA' ANd i just read this

...the tiMe IT TaKes to appEnd to a LIsT gROws lineaRlY wiTh thE SIze of The
  lISt, Whereas pRependINg WiTh :: takes CoNstant TiMe...

WHy eXactlY Does It take Linear tiMe to aPPend to append to A List but only coNStANT tIMe to PrePend to it. My cUrreNT gueSs is IT's SomEHow imPlemeNtED aS A linked list internalLy Which wOuld eXplain the diffErence betwEEN The two opEratIOnS. in that case, how aRe LisTBuffers imPLemented Which Have a conStant time APPend?

A:

TheRe's Two QueStiONS hEre: one is a very BASic oNe About liSts, And the oTheR is ScaLa-sPeCific. For tHe first, I'Ll
 as
(
  select GUID, No, s DateTime,eDate Tim e,Na me,
        case whe n  dat ediff(minute, 
                    coales c e( l a g(e Da te Tim e) ov er(pa rti tion by  GUID, Nam e                                              order  by  eDat eTime) ,  
                           s DateTime), 
                       s Da t eT i m e)<=10 
         th e n 0 
    e lse 1 
        end as M i nDi ff
  f ro m Y o urTabl e
),CS u mMi nDiff as
(  se lect GUID , No,s DateTim e , eDate Time,Nam e,
     su m( M inD i ff ) o v er( partitio nby  GUID , Na m e                        or der  bys Dat eTime  
                    rows between un boun ded prece din gand  c urren t  row)asGrp 
  from  CMinDi f f
) 
s e l e ct  C.GUID,
       (   select','+C2 . No 
     fro mCSu mMin D i ff as  C2     wher e C.GU I D=C2.GUID  a nd
         C.N a me =  C2.Na me and
          C.Grp =C 2.Grp
      o rd e r  b y  C2. No       forxmlp ath( ''), ty pe     ).va lu e (' s ubstring(text()[1],  2 )', 'v archa r(max)') as N o,
      m i n (C.sDate Time )  a s  sDateTime,
     max(C.eDat e Time) as  eDat eTime,
      C.N a m e
from C Sum Min Dif f a s Cgroup by C.GU I D , C. Na me, C.G rp
 Q:

W hyexa ctl y i sprepend t o a Scal aLi st  a  co nstan t  time op er ati on , b ut ap p end alinea r ti me  o p era tion?
I  a m in t he  m iddl e o flearn ingS cal a right  now from  Od e rsky 's  ' Program ming in Scala 'and I just  r ead  this. ..the ti me it takes to append t o  a list  gr ows l inea rly withthe  sizeoft he
  l ist, w herea spre p e nding w it h : :takes cons t a nttime. .. 

Wh y exact ly does it take li n ear  time to appe ndto a p p en d t o  a lis tb uto n ly constant tim e to prepe nd to  it. My cu r ren tguess i s it'ssomeh o w imple mented as  a linked  l isti n ter nally whic h wouldexplain t h e dif f er encebet ween t he  tw o ope ration s . I n tha t case ,how ar e Lis tB uffers i mplemented which have a  const ant t ime  append?
A: 
Th ere's two  que stions her e:one  is a  ve r y bas ic o n eabo u t lis ts,a nd the ot h er  is s ca la-specific . F orthe f irs t , I'll 
 as
(
_ select_GUID, No, sDateTime, eDateTime,_Name, 
__ __  _ case when_datediff(minute, 
  _  __             __ ___  coalesce(lag(eDateTime) over(partition by_GUID, Name 
  _ _       __  _        _     _  ___   _     _     _    order by eDateTime),_
     _    _ _    _  _ _  _     _  _  sDateTime), 
  __  ___ _  __ __     __   sDateTime) <= 10 
_   __   _ then 0 
 _     _ _ else_1 
         end_as MinDiff
  from YourTable
), CSumMinDiff_as
(
  select GUID,_No, sDateTime,_eDateTime,_Name, 
 __ _    sum(MinDiff) over(partition by_GUID, Name_
     _   __     _     _    order_by_sDateTime_
    _     _  _      __     rows_between_unbounded preceding and current row) as_Grp
__from CMinDiff
)
select C.GUID,
  _    (
 _     select ','+C2.No
  _  _ from CSumMinDiff as C2
___    where C.GUID = C2.GUID and
 _ _  _      C.Name = C2.Name and
_      _     C.Grp = C2.Grp
   _   order by C2.No
  _    for xml path(''),_type
   __  ).value('substring(text()[1], 2)', 'varchar(max)') as No,
____  _min(C.sDateTime) as sDateTime,
_  _ _ max(C.eDateTime) as_eDateTime,
 _  __ C.Name
from CSumMinDiff as C
group by C.GUID, C.Name, C.Grp

 Q:

Why exactly is prepend to a Scala List a_constant time operation, but append a_linear time operation?

I am in_the_middle of learning_Scala right now from_Odersky's 'Programming in Scala' and I just read_this

...the time it takes to append to a list_grows_linearly with_the size of the
_ list,_whereas prepending_with :: takes_constant time...

Why_exactly does_it take_linear time to append to append to_a_list but only constant time to prepend to it._My_current_guess_is it's somehow_implemented as a_linked list internally_which would explain_the_difference between the two operations. In_that case, how_are ListBuffers implemented which_have a constant time append?

A:

There's two questions here: one is_a very basic one about lists, and the other is scala-specific. For the first, I'll