/ Check-in [eb1fb420]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add implementation of nth_value() window function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | exp-window-functions
Files: files | file ages | folders
SHA3-256:eb1fb420ac70857e7ca4cbad78be15a27bee8f915ba2da080c7efa1879c06c31
User & Date: dan 2018-06-06 20:51:02
Context
2018-06-07
15:54
Fix problems with the nth_value() function. check-in: 63002b9a user: dan tags: exp-window-functions
2018-06-06
20:51
Add implementation of nth_value() window function. check-in: eb1fb420 user: dan tags: exp-window-functions
2018-06-05
16:16
Add implementation of last_value() window function. check-in: 2493ce1a user: dan tags: exp-window-functions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/window.c.

614
615
616
617
618
619
620

621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636











637
638
639
640
641
642
643
...
699
700
701
702
703
704
705
706


707
708
709
710
711
712
713
714
715
716




717
718
719
720
721
722
723
...
728
729
730
731
732
733
734
735


736
737
738
739
740
741
742





743
744
745
746
747
748
749
...
806
807
808
809
810
811
812


















































813
814
815
816
817
818
819
....
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
....
1199
1200
1201
1202
1203
1204
1205


1206
1207
1208
1209
1210
1211
1212
....
1232
1233
1234
1235
1236
1237
1238
1239

1240

1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254


1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271

1272
1273
1274
1275
1276
1277
1278
....
1493
1494
1495
1496
1497
1498
1499

1500


1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
  if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
  return 0;
}

static void windowAggInit(Parse *pParse, Window *pMWin){
  Window *pWin;
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){

    int funcFlags = pWin->pFunc->funcFlags;
    if( (funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
      ExprList *pList = pWin->pOwner->x.pList;
      KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
      Vdbe *v = sqlite3GetVdbe(pParse);
      pWin->csrApp = pParse->nTab++;
      pWin->regApp = pParse->nMem+1;
      pParse->nMem += 3;
      if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
        assert( pKeyInfo->aSortOrder[0]==0 );
        pKeyInfo->aSortOrder[0] = 1;
      }
      sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pWin->csrApp, 2);
      sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
    }











  }
}

void sqlite3WindowCodeInit(Parse *pParse, Window *pWin){
  Vdbe *v = sqlite3GetVdbe(pParse);
  int nPart = (pWin->pPartition ? pWin->pPartition->nExpr : 0);
  nPart += (pWin->pOrderBy ? pWin->pOrderBy->nExpr : 0);
................................................................................
        nArg++;
      }
    }else{
      assert( !(flags & SQLITE_FUNC_WINDOW_SIZE) );
      regArg = reg + pWin->iArgCol;
    }

    if( pWin->csrApp ){


      if( bInverse==0 ){
        sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
        sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
        sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
        sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
      }else{
        sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
        sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
        sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
      }




    }else{
      if( pWin->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
        CollSeq *pColl;
        pColl = sqlite3ExprCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
        sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
      }
      sqlite3VdbeAddOp3(v, OP_AggStep0, bInverse, regArg, pWin->regAccum);
................................................................................
}

static void windowAggFinal(Parse *pParse, Window *pMWin, int bFinal){
  Vdbe *v = sqlite3GetVdbe(pParse);
  Window *pWin;

  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    if( pWin->csrApp ){


      sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
      sqlite3VdbeAddOp1(v, OP_Last, pWin->csrApp);
      sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
      sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
      if( bFinal ){
        sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
      }





    }else{
      if( bFinal==0 ){
        sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
      }
      sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, pWin->nArg);
      sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
      if( bFinal ){
................................................................................

  /* End of the input loop */
  sqlite3WhereEnd(pWInfo);

  /* Invoke "flush_partition" to deal with the final (or only) partition */
  sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
}



















































/*
** ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
** ----------------------------------------------------
**
** Pseudo-code for the implementation of this window frame type is as
** follows. sqlite3WhereBegin() has already been called to generate the
................................................................................
    nPeerVal = pMWin->pOrderBy->nExpr;
    pParse->nMem += (2 * nPeerVal);
    for(k=0; k<nPeerVal; k++){
      sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, iPeer+k, regPeerVal+k);
    }
    sqlite3VdbeAddOp2(v, OP_Integer, 0, regPeer);
  }

  windowAggFinal(pParse, pMWin, 0);
  if( bRange ){
    sqlite3VdbeAddOp2(v, OP_AddImm, regPeer, 1);
  }
  sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
  sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)+2);
  sqlite3VdbeAddOp2(v, OP_Goto, 0, lblFlushDone);
  if( bRange ){
    KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy,0,0);
    int addrJump = sqlite3VdbeCurrentAddr(v)-4;
    for(k=0; k<nPeerVal; k++){
      int iOut = regPeerVal + nPeerVal + k;
................................................................................
  int csrLead;
  int regCtr;
  int regArg;                     /* Register array to martial function args */
  int regSize;
  int nArg;

  assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT) 


  );

  regNewPeer = pParse->nMem+1;
  pParse->nMem += nPeer;

  /* Allocate register and label for the "flush_partition" sub-routine. */
  regFlushPart = ++pParse->nMem;
................................................................................
  regArg = pParse->nMem+1;
  pParse->nMem += nArg;

  sqlite3VdbeAddOp2(v, OP_Integer, 0, regCtr);
  addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, csrLead);
  sqlite3VdbeAddOp1(v, OP_Rewind, pMWin->iEphCsr);

  if( pOrderBy ){

    int addrJump;                 /* Address of OP_Jump below */

    int iOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
    int regPeer = pMWin->regPart + (pPart ? pPart->nExpr : 0);
    KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);

    for(k=0; k<nPeer; k++){
      sqlite3VdbeAddOp3(v, OP_Column, csrLead, iOff+k, regNewPeer+k);
    }

    addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPeer, regPeer, nPeer);
    sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
    addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
    sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, nPeer-1);
    windowAggFinal(pParse, pMWin, 0);
    sqlite3VdbeAddOp3(v, OP_IfPos, regCtr, sqlite3VdbeCurrentAddr(v)+2 , 1);


    sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3);
    sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
    sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-3);
    sqlite3VdbeJumpHere(v, addrJump);
  }

  windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize);
  sqlite3VdbeAddOp2(v, OP_AddImm, regCtr, 1);

  sqlite3VdbeAddOp2(v, OP_Next, csrLead, addrRewind+2);

  windowAggFinal(pParse, pMWin, 1);

  sqlite3VdbeAddOp3(v, OP_IfPos, regCtr, sqlite3VdbeCurrentAddr(v)+2 , 1);
  sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3);
  sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
  sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-3);


  sqlite3VdbeJumpHere(v, addrRewind);
  sqlite3VdbeJumpHere(v, addrRewind+1);
  sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
  sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);

  /* Jump to here to skip over flush_partition */
................................................................................
   || (pMWin->eStart==TK_CURRENT&&pMWin->eEnd==TK_UNBOUNDED&&pMWin->pOrderBy)
  ){
    windowCodeRowExprStep(pParse, p, pWInfo, regGosub, addrGosub);
    return;
  }

  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){

    if( pWin->pFunc->funcFlags & SQLITE_FUNC_WINDOW_SIZE ){


      windowCodeCacheStep(pParse, p, pWInfo, regGosub, addrGosub);
      return;
    }
  }

  *pbLoop = 1;
  windowCodeDefaultStep(pParse, p, pWInfo, regGosub, addrGosub);
}









>
|
|


<











>
>
>
>
>
>
>
>
>
>
>







 







|
>
>










>
>
>
>







 







|
>
>







>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>




|







 







>
>







 







|
>
|
>
|
|
|
<
|
|
|
<
|
|
|
|
<
<
>
>
|
|
|
|




<


<
<
<
<
<
<
>







 







>
|
>
>









<
614
615
616
617
618
619
620
621
622
623
624
625

626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
...
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
...
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
...
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
....
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
....
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
....
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322

1323
1324
1325

1326
1327
1328
1329


1330
1331
1332
1333
1334
1335
1336
1337
1338
1339

1340
1341






1342
1343
1344
1345
1346
1347
1348
1349
....
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583

  if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
  return 0;
}

static void windowAggInit(Parse *pParse, Window *pMWin){
  Window *pWin;
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    Vdbe *v = sqlite3GetVdbe(pParse);
    FuncDef *p = pWin->pFunc;
    if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
      ExprList *pList = pWin->pOwner->x.pList;
      KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);

      pWin->csrApp = pParse->nTab++;
      pWin->regApp = pParse->nMem+1;
      pParse->nMem += 3;
      if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
        assert( pKeyInfo->aSortOrder[0]==0 );
        pKeyInfo->aSortOrder[0] = 1;
      }
      sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pWin->csrApp, 2);
      sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
    }
    else if( p->xSFunc==nth_valueStepFunc ){
      /* Allocate two registers at pWin->regApp. These will be used to
      ** store the start and end index of the current frame.  */
      assert( pMWin->iEphCsr );
      pWin->regApp = pParse->nMem+1;
      pWin->csrApp = pParse->nTab++;
      pParse->nMem += 2;
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
      sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
    }
  }
}

void sqlite3WindowCodeInit(Parse *pParse, Window *pWin){
  Vdbe *v = sqlite3GetVdbe(pParse);
  int nPart = (pWin->pPartition ? pWin->pPartition->nExpr : 0);
  nPart += (pWin->pOrderBy ? pWin->pOrderBy->nExpr : 0);
................................................................................
        nArg++;
      }
    }else{
      assert( !(flags & SQLITE_FUNC_WINDOW_SIZE) );
      regArg = reg + pWin->iArgCol;
    }

    if( (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX) 
      && pWin->eStart!=TK_UNBOUNDED 
    ){
      if( bInverse==0 ){
        sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
        sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
        sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
        sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
      }else{
        sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
        sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
        sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
      }
    }else if( pWin->regApp ){
      assert( pWin->pFunc->xSFunc==nth_valueStepFunc );
      assert( bInverse==0 || bInverse==1 );
      sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
    }else{
      if( pWin->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
        CollSeq *pColl;
        pColl = sqlite3ExprCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
        sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
      }
      sqlite3VdbeAddOp3(v, OP_AggStep0, bInverse, regArg, pWin->regAccum);
................................................................................
}

static void windowAggFinal(Parse *pParse, Window *pMWin, int bFinal){
  Vdbe *v = sqlite3GetVdbe(pParse);
  Window *pWin;

  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    if( (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX) 
     && pWin->eStart!=TK_UNBOUNDED 
    ){
      sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
      sqlite3VdbeAddOp1(v, OP_Last, pWin->csrApp);
      sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
      sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
      if( bFinal ){
        sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
      }
    }else if( pWin->regApp ){
      if( bFinal ){
        sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
        sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
      }
    }else{
      if( bFinal==0 ){
        sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
      }
      sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, pWin->nArg);
      sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
      if( bFinal ){
................................................................................

  /* End of the input loop */
  sqlite3WhereEnd(pWInfo);

  /* Invoke "flush_partition" to deal with the final (or only) partition */
  sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
}

static void windowReturnOneRow(
  Parse *pParse,
  Window *pMWin,
  int regGosub,
  int addrGosub
){
  Vdbe *v = sqlite3GetVdbe(pParse);
  Window *pWin;
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    FuncDef *pFunc = pWin->pFunc;
    if( pFunc->xSFunc==nth_valueStepFunc ){
      int csr = pWin->csrApp;
      int lbl = sqlite3VdbeMakeLabel(v);
      int tmpReg = sqlite3GetTempReg(pParse);
      sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
      sqlite3VdbeAddOp3(v, OP_Column, pWin->iEphCsr, pWin->iArgCol+1, tmpReg);
      sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
      sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
      sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
      sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
      sqlite3VdbeResolveLabel(v, lbl);
      sqlite3ReleaseTempReg(pParse, tmpReg);
    }
  }
  sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
}

static void windowReturnRows(
  Parse *pParse,
  Window *pMWin,
  int regCtr,
  int bFinal,
  int regGosub,
  int addrGosub,
  int regInvArg,
  int regInvSize
){
  int addr;
  Vdbe *v = sqlite3GetVdbe(pParse);
  windowAggFinal(pParse, pMWin, 0);
  addr = sqlite3VdbeAddOp3(v, OP_IfPos, regCtr, sqlite3VdbeCurrentAddr(v)+2 ,1);
  sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
  windowReturnOneRow(pParse, pMWin, regGosub, addrGosub);
  if( regInvArg ){
    windowAggStep(pParse, pMWin, pMWin->iEphCsr, 1, regInvArg, regInvSize);
  }
  sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, addr);
  sqlite3VdbeJumpHere(v, addr+1);   /* The OP_Goto */
}

/*
** ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
** ----------------------------------------------------
**
** Pseudo-code for the implementation of this window frame type is as
** follows. sqlite3WhereBegin() has already been called to generate the
................................................................................
    nPeerVal = pMWin->pOrderBy->nExpr;
    pParse->nMem += (2 * nPeerVal);
    for(k=0; k<nPeerVal; k++){
      sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, iPeer+k, regPeerVal+k);
    }
    sqlite3VdbeAddOp2(v, OP_Integer, 0, regPeer);
  }

  windowAggFinal(pParse, pMWin, 0);
  if( bRange ){
    sqlite3VdbeAddOp2(v, OP_AddImm, regPeer, 1);
  }
  windowReturnOneRow(pParse, pMWin, regGosub, addrGosub);
  sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)+2);
  sqlite3VdbeAddOp2(v, OP_Goto, 0, lblFlushDone);
  if( bRange ){
    KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy,0,0);
    int addrJump = sqlite3VdbeCurrentAddr(v)-4;
    for(k=0; k<nPeerVal; k++){
      int iOut = regPeerVal + nPeerVal + k;
................................................................................
  int csrLead;
  int regCtr;
  int regArg;                     /* Register array to martial function args */
  int regSize;
  int nArg;

  assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT) 
       || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED) 
       || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT) 
  );

  regNewPeer = pParse->nMem+1;
  pParse->nMem += nPeer;

  /* Allocate register and label for the "flush_partition" sub-routine. */
  regFlushPart = ++pParse->nMem;
................................................................................
  regArg = pParse->nMem+1;
  pParse->nMem += nArg;

  sqlite3VdbeAddOp2(v, OP_Integer, 0, regCtr);
  addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, csrLead);
  sqlite3VdbeAddOp1(v, OP_Rewind, pMWin->iEphCsr);

  if( pOrderBy && pMWin->eEnd==TK_CURRENT ){
    int bCurrent = (pMWin->eEnd==TK_CURRENT && pMWin->eStart==TK_CURRENT);
    int addrJump = 0;             /* Address of OP_Jump below */
    if( pMWin->eType==TK_RANGE ){
      int iOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
      int regPeer = pMWin->regPart + (pPart ? pPart->nExpr : 0);
      KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);

      for(k=0; k<nPeer; k++){
        sqlite3VdbeAddOp3(v, OP_Column, csrLead, iOff+k, regNewPeer+k);
      }

      addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPeer, regPeer, nPeer);
      sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
      addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
      sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, nPeer-1);


    }

    windowReturnRows(pParse, pMWin, regCtr, 0, regGosub, addrGosub, 
        (bCurrent ? regArg : 0), (bCurrent ? regSize : 0)
    );
    if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
  }

  windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize);
  sqlite3VdbeAddOp2(v, OP_AddImm, regCtr, 1);

  sqlite3VdbeAddOp2(v, OP_Next, csrLead, addrRewind+2);







  windowReturnRows(pParse, pMWin, regCtr, 1, regGosub, addrGosub, 0, 0);

  sqlite3VdbeJumpHere(v, addrRewind);
  sqlite3VdbeJumpHere(v, addrRewind+1);
  sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
  sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);

  /* Jump to here to skip over flush_partition */
................................................................................
   || (pMWin->eStart==TK_CURRENT&&pMWin->eEnd==TK_UNBOUNDED&&pMWin->pOrderBy)
  ){
    windowCodeRowExprStep(pParse, p, pWInfo, regGosub, addrGosub);
    return;
  }

  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    FuncDef *pFunc = pWin->pFunc;
    if( (pFunc->funcFlags & SQLITE_FUNC_WINDOW_SIZE)
     || (pFunc->xSFunc==nth_valueStepFunc)
    ){
      windowCodeCacheStep(pParse, p, pWInfo, regGosub, addrGosub);
      return;
    }
  }

  *pbLoop = 1;
  windowCodeDefaultStep(pParse, p, pWInfo, regGosub, addrGosub);
}


Changes to test/window3.tcl.

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
201
202
203
204
205
206
207


















208
209
210
211
  execsql_float_test 1.$tn.7.4 "
    SELECT percent_rank() OVER ( PARTITION BY b%10 ORDER BY b $window ) FROM t2
  "
  execsql_float_test 1.$tn.7.5 "
    SELECT percent_rank() OVER ( ORDER BY b%10 $window ) FROM t2
  "
  execsql_float_test 1.$tn.7.6 "
    SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 $window ) FROM t2
  "

  execsql_float_test 1.$tn.8.1 "
    SELECT cume_dist() OVER ( ORDER BY a $window ) FROM t2
  "
  execsql_float_test 1.$tn.8.2 "
    SELECT cume_dist() OVER ( PARTITION BY b%10 ORDER BY a $window ) FROM t2
................................................................................
  execsql_test 1.$tn.9.5 "
    SELECT last_value(a+b) OVER ( ORDER BY b%10,a $window ) FROM t2
  "
  execsql_test 1.$tn.9.6 "
    SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 $window) FROM t2
  "



















}

finish_test








|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
  execsql_float_test 1.$tn.7.4 "
    SELECT percent_rank() OVER ( PARTITION BY b%10 ORDER BY b $window ) FROM t2
  "
  execsql_float_test 1.$tn.7.5 "
    SELECT percent_rank() OVER ( ORDER BY b%10 $window ) FROM t2
  "
  execsql_float_test 1.$tn.7.6 "
    SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 $window) FROM t2
  "

  execsql_float_test 1.$tn.8.1 "
    SELECT cume_dist() OVER ( ORDER BY a $window ) FROM t2
  "
  execsql_float_test 1.$tn.8.2 "
    SELECT cume_dist() OVER ( PARTITION BY b%10 ORDER BY a $window ) FROM t2
................................................................................
  execsql_test 1.$tn.9.5 "
    SELECT last_value(a+b) OVER ( ORDER BY b%10,a $window ) FROM t2
  "
  execsql_test 1.$tn.9.6 "
    SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 $window) FROM t2
  "

  execsql_test 1.$tn.10.1 "
    SELECT nth_value(b,b+1) OVER (ORDER BY a $window) FROM t2
  "
  execsql_test 1.$tn.9.2 "
    SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a $window) FROM t2
  "
  execsql_test 1.$tn.9.3 "
    SELECT nth_value(b,b+1) OVER ( ORDER BY b,a $window ) FROM t2
  "
  execsql_test 1.$tn.9.4 "
    SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a $window ) FROM t2
  "
  execsql_test 1.$tn.9.5 "
    SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a $window ) FROM t2
  "
  execsql_test 1.$tn.9.6 "
    SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 $window) FROM t2
  "
}

finish_test

Changes to test/window3.test.

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
293
294
295
296
297
298
299
























300
301
302
303
304
305
306
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
...
533
534
535
536
537
538
539
























540
541
542
543
544
545
546
...
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
...
773
774
775
776
777
778
779
























780
781
782
783
784
785
786
...
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
....
1013
1014
1015
1016
1017
1018
1019
























1020
1021
1022
1023
1024
1025
1026
....
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
....
1253
1254
1255
1256
1257
1258
1259
























1260
1261
1262
1263
1264
1265
1266
....
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
....
1493
1494
1495
1496
1497
1498
1499
























1500
1501
1502
1503
1504
1505
1506
....
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
....
1733
1734
1735
1736
1737
1738
1739
























1740
1741
1742
1743
1744
1745
1746
....
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
....
1973
1974
1975
1976
1977
1978
1979
























1980
1981
1982
1983
1984
1985
1986
....
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
....
2213
2214
2215
2216
2217
2218
2219
























2220
2221
2222
2223
2224
2225
2226
....
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
....
2453
2454
2455
2456
2457
2458
2459
























2460
2461
2462
2463
2464
2465
2466
....
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
....
2693
2694
2695
2696
2697
2698
2699
























2700
2701
2702
2703
2704
2705
2706
....
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
....
2933
2934
2935
2936
2937
2938
2939
























2940
2941
2942
2943
2944
2945
2946
....
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
....
3173
3174
3175
3176
3177
3178
3179
























3180
3181
3182
3183
3184
3185
3186
....
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
....
3413
3414
3415
3416
3417
3418
3419
























3420
3421
3422
3423
3424
3425
3426
....
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
....
3653
3654
3655
3656
3657
3658
3659
























3660
3661
3662
3663
3664
3665
3666
....
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
....
3893
3894
3895
3896
3897
3898
3899
























3900
3901
3902
3903
3904
3905
3906
....
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
....
4133
4134
4135
4136
4137
4138
4139
























4140
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.1.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.1.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.1.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.2.2.1 {
  SELECT max(b) OVER ( ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.2.2.2 {
  SELECT min(b) OVER ( ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.2.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.2.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.2.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.3.2.1 {
  SELECT max(b) OVER ( ORDER BY a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   74   41   74   23   99   26   33   2   89   81   96   59   38   68   39   62   91   46   6   99   97   27   46   78   54   97   8   67   29   93   84   77   23   16   16   93   65   35   47   7   86   74   61   91   85   24   85   43   59   12   32   56   3   91   22   90   55   15   28   89   25   47   1   56   40   43   56   16   75   36   89   98   76   81   4   94   42   30   78   33   29   53   63   2   87   37   80   84   72   41   9   61   73   95   65   13   58   96   98   1   21   74   65   35   5   73   11   51   87   41   12   8   20   31   31   15   95   22   73   79   88   34   8   11   49   34   90   59   96   60   55   75   77   44   2   7   85   57   74   29   70   59   19   39   26   26   47   80   90   36   58   47   9   72   72   66   33   93   75   64   81   9   23   37   13   12   14   62   91   36   91   33   15   34   36   99   3   95   69   58   52   30   50   84   10   84   33   21   39   44   58   30   38   34   83   27   82   17   7}

do_execsql_test 1.3.2.2 {
  SELECT min(b) OVER ( ORDER BY a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   74   41   74   23   99   26   33   2   89   81   96   59   38   68   39   62   91   46   6   99   97   27   46   78   54   97   8   67   29   93   84   77   23   16   16   93   65   35   47   7   86   74   61   91   85   24   85   43   59   12   32   56   3   91   22   90   55   15   28   89   25   47   1   56   40   43   56   16   75   36   89   98   76   81   4   94   42   30   78   33   29   53   63   2   87   37   80   84   72   41   9   61   73   95   65   13   58   96   98   1   21   74   65   35   5   73   11   51   87   41   12   8   20   31   31   15   95   22   73   79   88   34   8   11   49   34   90   59   96   60   55   75   77   44   2   7   85   57   74   29   70   59   19   39   26   26   47   80   90   36   58   47   9   72   72   66   33   93   75   64   81   9   23   37   13   12   14   62   91   36   91   33   15   34   36   99   3   95   69   58   52   30   50   84   10   84   33   21   39   44   58   30   38   34   83   27   82   17   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.3.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.3.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.3.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.4.2.1 {
  SELECT max(b) OVER ( ORDER BY a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   83   83   83   83   83   83   83   83   83   82   82   17   7}

do_execsql_test 1.4.2.2 {
  SELECT min(b) OVER ( ORDER BY a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.4.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.4.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.4.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.5.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   0   74   74   74   74   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.5.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.5.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.5.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163}

do_execsql_test 1.5.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

























do_execsql_test 1.6.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   0   74   74   74   74   99   99   99   33   89   89   96   96   96   68   68   68   91   91   91   99   99   99   97   78   78   97   97   97   67   93   93   93   84   77   23   93   93   93   65   47   86   86   86   91   91   91   85   85   85   59   59   56   56   91   91   91   90   90   55   89   89   89   47   56   56   56   56   56   75   75   89   98   98   98   81   94   94   94   78   78   78   53   63   63   87   87   87   84   84   84   72   61   73   95   95   95   65   96   98   98   98   74   74   74   65   73   73   73   87   87   87   41   20   31   31   31   95   95   95   79   88   88   88   34   49   49   90   90   96   96   96   75   77   77   77   44   85   85   85   74   74   70   70   59   39   39   47   80   90   90   90   58   58   72   72   72   72   93   93   93   81   81   81   37   37   37   14   62   91   91   91   91   91   34   36   99   99   99   95   95   69   58   52   84   84   84   84   84   39   44   58   58   58   38   83   83   83}

do_execsql_test 1.6.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   0   0   0   41   23   23   23   26   2   2   2   81   59   38   38   38   39   39   46   6   6   6   27   27   27   46   54   8   8   8   29   29   77   23   16   16   16   16   35   35   7   7   7   61   61   61   24   24   24   43   12   12   12   3   3   3   22   22   15   15   15   25   25   1   1   1   40   40   16   16   16   36   36   76   76   4   4   4   30   30   30   29   29   29   2   2   2   37   37   72   41   9   9   9   61   65   13   13   13   58   1   1   1   21   35   5   5   5   11   11   41   12   8   8   8   20   15   15   15   22   22   73   34   8   8   8   11   34   34   59   59   55   55   55   44   2   2   2   7   57   29   29   29   19   19   19   26   26   26   47   36   36   36   9   9   9   66   33   33   33   64   64   9   9   9   13   12   12   12   14   36   36   33   15   15   15   34   3   3   3   58   52   30   30   30   10   10   10   21   21   21   39   30   30   30   34   27   27}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.6.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.6.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276}

do_execsql_test 1.6.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

























do_execsql_test 1.7.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   74   74   74   74   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.7.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.7.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.7.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.7.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.8.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {0   74   74   74   74   99   99   99   99   99   89   96   96   96   96   96   68   91   91   91   99   99   99   99   99   97   97   97   97   97   97   93   93   93   93   84   93   93   93   93   93   86   86   86   91   91   91   91   91   85   85   85   59   59   91   91   91   91   91   90   90   89   89   89   89   56   56   56   56   75   75   89   98   98   98   98   98   94   94   94   94   78   78   78   63   87   87   87   87   87   84   84   84   73   95   95   95   95   96   98   98   98   98   98   74   74   74   73   73   87   87   87   87   87   41   31   31   95   95   95   95   95   88   88   88   88   49   90   90   96   96   96   96   96   77   77   77   85   85   85   85   85   74   74   70   70   59   47   80   90   90   90   90   90   72   72   72   72   93   93   93   93   93   81   81   81   37   37   62   91   91   91   91   91   91   91   99   99   99   99   99   95   95   69   84   84   84   84   84   84   84   58   58   58   58   83   83   83   83   83}

do_execsql_test 1.8.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {0   0   0   0   0   23   23   23   2   2   2   2   2   38   38   38   38   38   39   6   6   6   6   6   27   27   27   8   8   8   8   8   29   23   16   16   16   16   16   16   7   7   7   7   7   61   24   24   24   24   12   12   12   3   3   3   3   3   15   15   15   15   15   1   1   1   1   1   16   16   16   16   16   36   36   4   4   4   4   4   30   29   29   29   2   2   2   2   2   37   37   9   9   9   9   9   13   13   13   13   1   1   1   1   1   5   5   5   5   5   11   11   8   8   8   8   8   15   15   15   15   22   22   8   8   8   8   8   11   34   34   55   55   55   44   2   2   2   2   2   7   29   29   19   19   19   19   19   26   26   26   36   36   9   9   9   9   9   33   33   33   33   9   9   9   9   9   12   12   12   12   14   33   15   15   15   15   3   3   3   3   3   30   30   30   10   10   10   10   10   21   21   21   30   30   30   27   27   17   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.8.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.8.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.8.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.9.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   74   41   74   23   99   26   33   2   89   81   96   59   38   68   39   62   91   46   6   99   97   27   46   78   54   97   8   67   29   93   84   77   23   16   16   93   65   35   47   7   86   74   61   91   85   24   85   43   59   12   32   56   3   91   22   90   55   15   28   89   25   47   1   56   40   43   56   16   75   36   89   98   76   81   4   94   42   30   78   33   29   53   63   2   87   37   80   84   72   41   9   61   73   95   65   13   58   96   98   1   21   74   65   35   5   73   11   51   87   41   12   8   20   31   31   15   95   22   73   79   88   34   8   11   49   34   90   59   96   60   55   75   77   44   2   7   85   57   74   29   70   59   19   39   26   26   47   80   90   36   58   47   9   72   72   66   33   93   75   64   81   9   23   37   13   12   14   62   91   36   91   33   15   34   36   99   3   95   69   58   52   30   50   84   10   84   33   21   39   44   58   30   38   34   83   27   82   17   7}

do_execsql_test 1.9.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   74   41   74   23   99   26   33   2   89   81   96   59   38   68   39   62   91   46   6   99   97   27   46   78   54   97   8   67   29   93   84   77   23   16   16   93   65   35   47   7   86   74   61   91   85   24   85   43   59   12   32   56   3   91   22   90   55   15   28   89   25   47   1   56   40   43   56   16   75   36   89   98   76   81   4   94   42   30   78   33   29   53   63   2   87   37   80   84   72   41   9   61   73   95   65   13   58   96   98   1   21   74   65   35   5   73   11   51   87   41   12   8   20   31   31   15   95   22   73   79   88   34   8   11   49   34   90   59   96   60   55   75   77   44   2   7   85   57   74   29   70   59   19   39   26   26   47   80   90   36   58   47   9   72   72   66   33   93   75   64   81   9   23   37   13   12   14   62   91   36   91   33   15   34   36   99   3   95   69   58   52   30   50   84   10   84   33   21   39   44   58   30   38   34   83   27   82   17   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.9.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.9.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.9.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.10.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {74   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.10.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.10.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.10.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229   229   229   229   229}

do_execsql_test 1.10.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.11.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {74   74   74   99   99   99   99   99   99   99   96   96   96   96   96   96   91   91   99   99   99   99   99   99   99   97   97   97   97   97   97   93   93   93   93   93   93   93   93   93   93   86   91   91   91   91   91   91   91   85   85   85   91   91   91   91   91   91   91   90   90   89   89   89   89   56   56   75   75   89   98   98   98   98   98   98   98   94   94   94   94   78   78   87   87   87   87   87   87   87   84   84   95   95   95   95   96   98   98   98   98   98   98   98   74   74   74   87   87   87   87   87   87   87   41   95   95   95   95   95   95   95   88   88   88   90   90   96   96   96   96   96   96   96   77   85   85   85   85   85   85   85   74   74   70   70   80   90   90   90   90   90   90   90   72   72   93   93   93   93   93   93   93   81   81   81   62   91   91   91   91   91   91   91   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   58   58   83   83   83   83   83   83   83}

do_execsql_test 1.11.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {0   0   0   0   0   23   2   2   2   2   2   2   2   38   38   38   38   6   6   6   6   6   6   6   27   8   8   8   8   8   8   8   16   16   16   16   16   16   7   7   7   7   7   7   7   24   24   24   12   12   12   3   3   3   3   3   3   3   15   15   15   1   1   1   1   1   1   1   16   16   16   16   16   4   4   4   4   4   4   4   29   29   2   2   2   2   2   2   2   9   9   9   9   9   9   9   13   13   1   1   1   1   1   1   1   5   5   5   5   5   8   8   8   8   8   8   8   15   15   15   15   8   8   8   8   8   8   8   11   34   34   55   44   2   2   2   2   2   2   2   7   19   19   19   19   19   19   19   26   26   26   9   9   9   9   9   9   9   33   33   9   9   9   9   9   9   9   12   12   12   12   14   15   15   15   3   3   3   3   3   3   3   30   10   10   10   10   10   10   10   21   21   21   30   27   27   17   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.11.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.11.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229   229   229}

do_execsql_test 1.11.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.12.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {74   99   99   99   99   99   89   96   96   96   96   96   68   91   91   91   99   99   99   99   99   97   97   97   97   97   97   93   93   93   93   84   93   93   93   93   93   86   86   86   91   91   91   91   91   85   85   85   59   59   91   91   91   91   91   90   90   89   89   89   89   56   56   56   56   75   75   89   98   98   98   98   98   94   94   94   94   78   78   78   63   87   87   87   87   87   84   84   84   73   95   95   95   95   96   98   98   98   98   98   74   74   74   73   73   87   87   87   87   87   41   31   31   95   95   95   95   95   88   88   88   88   49   90   90   96   96   96   96   96   77   77   77   85   85   85   85   85   74   74   70   70   59   47   80   90   90   90   90   90   72   72   72   72   93   93   93   93   93   81   81   81   37   37   62   91   91   91   91   91   91   91   99   99   99   99   99   95   95   69   84   84   84   84   84   84   84   58   58   58   58   83   83   83   83   83   82   82   17   7}

do_execsql_test 1.12.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {0   23   23   23   2   2   2   2   2   38   38   38   38   38   39   6   6   6   6   6   27   27   27   8   8   8   8   8   29   23   16   16   16   16   16   16   7   7   7   7   7   61   24   24   24   24   12   12   12   3   3   3   3   3   15   15   15   15   15   1   1   1   1   1   16   16   16   16   16   36   36   4   4   4   4   4   30   29   29   29   2   2   2   2   2   37   37   9   9   9   9   9   13   13   13   13   1   1   1   1   1   5   5   5   5   5   11   11   8   8   8   8   8   15   15   15   15   22   22   8   8   8   8   8   11   34   34   55   55   55   44   2   2   2   2   2   7   29   29   19   19   19   19   19   26   26   26   36   36   9   9   9   9   9   33   33   33   33   9   9   9   9   9   12   12   12   12   14   33   15   15   15   15   3   3   3   3   3   30   30   30   10   10   10   10   10   21   21   21   30   30   30   27   27   17   7   7   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.12.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.12.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229   229   229   229   229}

do_execsql_test 1.12.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.13.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {74   99   99   99   33   89   89   96   96   96   68   68   68   91   91   91   99   99   99   97   78   78   97   97   97   67   93   93   93   84   77   23   93   93   93   65   47   86   86   86   91   91   91   85   85   85   59   59   56   56   91   91   91   90   90   55   89   89   89   47   56   56   56   56   56   75   75   89   98   98   98   81   94   94   94   78   78   78   53   63   63   87   87   87   84   84   84   72   61   73   95   95   95   65   96   98   98   98   74   74   74   65   73   73   73   87   87   87   41   20   31   31   31   95   95   95   79   88   88   88   34   49   49   90   90   96   96   96   75   77   77   77   44   85   85   85   74   74   70   70   59   39   39   47   80   90   90   90   58   58   72   72   72   72   93   93   93   81   81   81   37   37   37   14   62   91   91   91   91   91   34   36   99   99   99   95   95   69   58   52   84   84   84   84   84   39   44   58   58   58   38   83   83   83   82   82   17   7   {}   {}}

do_execsql_test 1.13.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {23   23   23   26   2   2   2   81   59   38   38   38   39   39   46   6   6   6   27   27   27   46   54   8   8   8   29   29   77   23   16   16   16   16   35   35   7   7   7   61   61   61   24   24   24   43   12   12   12   3   3   3   22   22   15   15   15   25   25   1   1   1   40   40   16   16   16   36   36   76   76   4   4   4   30   30   30   29   29   29   2   2   2   37   37   72   41   9   9   9   61   65   13   13   13   58   1   1   1   21   35   5   5   5   11   11   41   12   8   8   8   20   15   15   15   22   22   73   34   8   8   8   11   34   34   59   59   55   55   55   44   2   2   2   7   57   29   29   29   19   19   19   26   26   26   47   36   36   36   9   9   9   66   33   33   33   64   64   9   9   9   13   12   12   12   14   36   36   33   15   15   15   34   3   3   3   58   52   30   30   30   10   10   10   21   21   21   39   30   30   30   34   27   27   17   7   7   7   {}   {}}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.13.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.13.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229   229   229   {}   {}}

do_execsql_test 1.13.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

























do_execsql_test 1.14.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.14.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.14.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.14.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.14.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.15.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   83   83   83   83   83   83   83   83   83}

do_execsql_test 1.15.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {0   0   0   0   0   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.15.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.15.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.15.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.16.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   83   83   83   83   83   83   83   83   83   82   82   17   7}

do_execsql_test 1.16.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.16.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.16.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.16.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

























do_execsql_test 1.17.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   83   83   83   83   83   83   83   83   83   82   82   17   7   {}   {}   {}   {}}

do_execsql_test 1.17.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   {}   {}   {}   {}}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.17.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER ( PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.17.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   {}   {}   {}   {}}

do_execsql_test 1.17.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

























finish_test







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
...
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
...
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
...
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
...
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
...
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
....
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
....
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
....
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
....
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
....
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
....
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
....
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
....
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
....
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
....
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
....
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
....
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
....
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
....
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
....
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
....
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
....
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
....
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
....
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
....
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
....
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
....
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
....
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
....
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
....
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
....
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
....
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.1.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.1.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.1.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.1.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   41   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   2   {}   29   {}   {}   {}   46   62   62   {}   {}   16   {}   33   {}   {}   {}   {}   {}   78   {}   61   {}   59   77   {}   74   {}   27   {}   22   39   67   {}   54   85   74   90   7   61   90   62   {}   93   {}   {}   {}   {}   23   {}   74   93   30   23   29   3   1   41   {}   65   33   2   98   86   89   25   76   {}   40   38   15   13   96   74   97   81   40   16   99   76   96   32   80   86   59   2   99   84   84   39   65   27   76   78   84   16   2   96   59   16   41   28   13   89   22   4   42   91   41   33   87   55   81   29   36   28   6   47   97   97   85   33   41   93   15   85   89   98   98   43   23   73   4   56   29   89   46   65   38   59   68   47   9   93   9   23   39   16   93   98   74   65   75   15   56   93   12   2   81   2   23   97   47   91   15   93   35   16   63   8   53   91   33}

do_execsql_test 1.1.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   81   {}   21   {}   {}   {}   {}   21   {}   {}   {}   21   {}   {}   {}   {}   {}   {}   12   {}   {}   {}   12   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   23   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   73   {}   23   {}   {}   {}   {}   {}   {}   {}   {}   74   {}   {}   {}   {}   {}   {}   {}   {}   64   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   15   {}   {}   {}   {}   {}   {}   55   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   27   47   {}   {}   {}   {}   {}   {}   {}   {}   {}   98   {}   98   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   29   {}   {}   {}   {}   {}   {}   {}   29   29   {}   {}   {}}

do_execsql_test 1.1.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   1   1   1   1   1   2   2   2   2   3   3   3   3   4   4   4   5   5   5   6   7   7   7   7   7   7   7   8   8   8   8   8   8   8   9   9   10   11   11   11   11   12   12   12   12   12   13   13   13   13   13   14   15   15   15   15   15   15   15   15   16   16   16   16   16   16   16   16   16   16   17   17   19   19   19   19   20   20   21   21   21   21   21   22   22   22   22   23   23   23   23   23   25   25   26   26   26   26   26   27   27   28   29   29   29   29   30   30   30   30   30   30   30   30   31   31   31   31   31   32   32   33   33   33   33   33   33   33   33   34   34   34   34   35   35   35   36   36   36   36   36   36   36   36   36   36   36   36   37   37   37   37   38   38   38   39   39   39   39   39   40   40   40   40   41   41   41   41   41   41   42   43   43   43   43   43   43   44   44   44   44   44   46   46   46   46   47   47   47   47   47   47   47   47   47   47   49   49   49}

do_execsql_test 1.1.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.1.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   90   1   30   {}   {}   {}   31   30   {}   {}   {}   1   40   {}   50   11   81   42   40   {}   50   81   40   {}   {}   50   {}   52   {}   41   81   {}   41   {}   2   30   2   81   82   53   {}   10   {}   {}   81   {}   41   10   81   30   81   {}   3   3   23   {}   3   61   80   {}   94   3   91   91   72   3   63   30   91   94   94   72   91   73   91   84   84   33   41   1   33   84   73   73   91   20   41   84   33   33   84   33   41   84   21   44   22   90   22   81   81   74   93   93   93   81   21   83   44   44   21   21   21   13   21   21   34   11   34   73   74   2   60   2   34   2   34   74   60   23   2   2   2   11   91   60   62   73   74   70   51   65   74   93   65   70   34   70   93   93   93   62   35   44   43   12   35   41   43   44   44   41   80   54   72   43   41   43   91   12   80   80   35   33   12}

do_execsql_test 1.1.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.2.2.1 {
  SELECT max(b) OVER ( ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.2.2.2 {
  SELECT min(b) OVER ( ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.2.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.2.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.2.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.2.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {0   81   86   81   46   98   97   23   41   72   29   13   28   35   16   47   47   9   24   26   98   58   8   24   30   91   58   2   56   29   73   2   42   46   62   62   73   40   16   85   33   37   81   25   9   87   78   87   61   28   59   77   90   74   9   27   41   22   39   67   72   54   85   74   90   7   61   90   62   4   93   72   96   94   29   23   95   74   93   30   23   29   3   1   41   80   65   33   2   98   86   89   25   76   65   40   38   15   13   96   74   97   81   40   16   99   76   96   32   80   86   59   2   99   84   84   39   65   27   76   78   84   16   2   96   59   16   41   28   13   89   22   4   42   91   41   33   87   55   81   29   36   28   6   47   97   97   85   33   41   93   15   85   89   98   98   43   23   73   4   56   29   89   46   65   38   59   68   47   9   93   9   23   39   16   93   98   74   65   75   15   56   93   12   2   81   2   23   97   47   91   15   93   35   16   63   8   53   91   33}

do_execsql_test 1.2.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   81   21   21   {}   {}   {}   {}   21   {}   {}   {}   21   12   {}   72   {}   {}   {}   12   {}   72   {}   12   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   23   {}   {}   {}   {}   {}   73   {}   {}   {}   {}   {}   73   {}   23   {}   {}   {}   {}   {}   {}   {}   {}   74   {}   {}   {}   {}   {}   {}   {}   {}   64   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   55   {}   {}   {}   {}   {}   {}   15   55   {}   {}   {}   {}   {}   55   {}   {}   {}   {}   16   {}   26   26   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   27   47   {}   {}   {}   98   {}   {}   {}   {}   {}   98   {}   98   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   29   {}   {}   {}   {}   {}   9   {}   29   29   {}   {}   {}}

do_execsql_test 1.2.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   1   1   1   1   2   2   2   2   3   3   3   3   4   4   4   5   5   5   6   7   7   7   7   7   7   7   8   8   8   8   8   8   8   9   9   10   11   11   11   11   12   12   12   12   12   13   13   13   13   13   14   15   15   15   15   15   15   15   15   16   16   16   16   16   16   16   16   16   16   17   17   19   19   19   19   20   20   21   21   21   21   21   22   22   22   22   23   23   23   23   23   25   25   26   26   26   26   26   27   27   28   29   29   29   29   30   30   30   30   30   30   30   30   31   31   31   31   31   32   32   33   33   33   33   33   33   33   33   34   34   34   34   35   35   35   36   36   36   36   36   36   36   36   36   36   36   36   37   37   37   37   38   38   38   39   39   39   39   39   40   40   40   40   41   41   41   41   41   41   42   43   43   43   43   43   43   44   44   44   44   44   46   46   46   46   47   47   47   47   47   47   47   47   47   47   49   49   49}

do_execsql_test 1.2.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   80   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   1   51   51   91   91   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   2   2   62   62   62   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   13   13   43   43   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   74   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   35   85   85   85   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   66   66   66   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   37   37   37   87   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   58   58   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   39   39   39   89   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.2.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   74   32   31   84   91   74   3   93   84   74   31   12   90   31   22   74   64   43   64   64   90   74   22   43   90   1   30   62   22   31   31   30   74   64   64   1   40   33   50   11   81   42   40   13   50   81   40   13   13   50   33   52   24   41   81   34   41   34   2   30   2   81   82   53   33   10   33   33   81   34   41   10   81   30   81   4   3   3   23   94   3   61   80   84   94   3   91   91   72   3   63   30   91   94   94   72   91   73   91   84   84   33   41   1   33   84   73   73   91   20   41   84   33   33   84   33   41   84   21   44   22   90   22   81   81   74   93   93   93   81   21   83   44   44   21   21   21   13   21   21   34   11   34   73   74   2   60   2   34   2   34   74   60   23   2   2   2   11   91   60   62   73   74   70   51   65   74   93   65   70   34   70   93   93   93   62   35   44   43   12   35   41   43   44   44   41   80   54   72   43   41   43   91   12   80   80   35   33   12}

do_execsql_test 1.2.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.3.2.1 {
  SELECT max(b) OVER ( ORDER BY a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   74   41   74   23   99   26   33   2   89   81   96   59   38   68   39   62   91   46   6   99   97   27   46   78   54   97   8   67   29   93   84   77   23   16   16   93   65   35   47   7   86   74   61   91   85   24   85   43   59   12   32   56   3   91   22   90   55   15   28   89   25   47   1   56   40   43   56   16   75   36   89   98   76   81   4   94   42   30   78   33   29   53   63   2   87   37   80   84   72   41   9   61   73   95   65   13   58   96   98   1   21   74   65   35   5   73   11   51   87   41   12   8   20   31   31   15   95   22   73   79   88   34   8   11   49   34   90   59   96   60   55   75   77   44   2   7   85   57   74   29   70   59   19   39   26   26   47   80   90   36   58   47   9   72   72   66   33   93   75   64   81   9   23   37   13   12   14   62   91   36   91   33   15   34   36   99   3   95   69   58   52   30   50   84   10   84   33   21   39   44   58   30   38   34   83   27   82   17   7}

do_execsql_test 1.3.2.2 {
  SELECT min(b) OVER ( ORDER BY a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   74   41   74   23   99   26   33   2   89   81   96   59   38   68   39   62   91   46   6   99   97   27   46   78   54   97   8   67   29   93   84   77   23   16   16   93   65   35   47   7   86   74   61   91   85   24   85   43   59   12   32   56   3   91   22   90   55   15   28   89   25   47   1   56   40   43   56   16   75   36   89   98   76   81   4   94   42   30   78   33   29   53   63   2   87   37   80   84   72   41   9   61   73   95   65   13   58   96   98   1   21   74   65   35   5   73   11   51   87   41   12   8   20   31   31   15   95   22   73   79   88   34   8   11   49   34   90   59   96   60   55   75   77   44   2   7   85   57   74   29   70   59   19   39   26   26   47   80   90   36   58   47   9   72   72   66   33   93   75   64   81   9   23   37   13   12   14   62   91   36   91   33   15   34   36   99   3   95   69   58   52   30   50   84   10   84   33   21   39   44   58   30   38   34   83   27   82   17   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.3.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.3.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.3.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.3.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.3.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.3.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.3.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.3.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a RANGE BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.3.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.4.2.1 {
  SELECT max(b) OVER ( ORDER BY a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   83   83   83   83   83   83   83   83   83   82   82   17   7}

do_execsql_test 1.4.2.2 {
  SELECT min(b) OVER ( ORDER BY a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.4.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.4.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.4.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.4.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {0   4   61   42   8   35   77   7   81   96   9   11   89   32   53   91   30   51   56   54   73   22   59   75   74   78   8   16   65   15   8   31   87   90   12   32   96   74   76   37   85   90   15   35   2   60   36   75   9   51   47   63   51   90   26   42   26   8   76   80   90   37   87   56   79   5   87   8   2   39   73   64   36   90   72   78   36   73   51   33   20   41   2   26   37   33   8   14   33   81   55   1   9   12   39   64   87   72   34   82   21   34   99   62   74   41   69   22   75   27   58   8   79   77   26   26   55   {}   29   30   7   {}   66   55   2   34   64   {}   33   {}   44   84   {}   {}   95   85   19   {}   83   {}   91   {}   {}   9   50   91   33   34   {}   {}   84   {}   7   9   {}   {}   {}   44   {}   {}   {}   {}   91   84   {}   95   95   52   {}   {}   {}   {}   {}   21   {}   {}   {}   58   {}   {}   {}   {}   {}   {}   {}   83   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.4.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   21   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   12   {}   62   {}   {}   {}   12   {}   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   53   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   95   {}   {}   {}   {}   {}   {}   85   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   56   {}   36   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   57   {}   {}   {}   {}   {}   7   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   8   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   9   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.4.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   2   2   3   3   5   6   7   8   8   9   9   10   11   12   12   13   13   14   15   16   16   17   19   20   21   22   23   23   24   25   26   26   27   28   29   30   31   31   33   33   33   33   34   34   35   36   36   36   37   37   38   39   39   40   41   41   42   43   44   46   47   47   47   47   49   51   52   53   54   55   56   56   57   58   58   58   59   59   59   61   61   62   63   65   65   65   67   69   70   72   72   73   74   74   74   74   75   76   77   78   80   81   81   83   84   84   84   85   85   87   87   88   89   89   90   90   90   91   91   91   93   93   95   95   96   96   97   98   99   99   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.4.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   80   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   11   61   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   12   12   72   82   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   13   23   63   73   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   74   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   35   85   85   95   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   76   86   96   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   37   47   47   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   58   68   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   39   49   59   99   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.4.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   64   42   81   94   1   44   73   74   44   85   22   33   41   72   93   34   65   54   5   15   81   15   63   84   21   2   62   54   93   43   33   2   75   16   86   23   12   85   62   13   53   94   12   75   23   73   72   96   46   33   55   25   26   74   34   87   84   87   55   53   25   84   75   56   66   54   36   97   55   78   84   84   95   74   65   17   87   77   96   8   47   95   34   89   98   7   46   6   96   8   47   95   56   89   59   36   36   78   96   89   29   37   95   56   39   {}   8   58   67   85   86   {}   58   49   {}   29   76   {}   77   {}   78   56   98   36   97   {}   59   89   89   47   78   {}   {}   {}   38   68   58   {}   58   38   {}   98   {}   {}   {}   19   57   9   {}   9   {}   {}   7   {}   {}   {}   39   89   38   78   39   {}   {}   8   19   {}   {}   {}   {}   89   {}   39   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   9   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.4.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 RANGE BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.5.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   0   74   74   74   74   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.5.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.5.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.5.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163}

do_execsql_test 1.5.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.5.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   41   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   2   {}   {}   {}   {}   {}   46   62   62   {}   {}   {}   {}   33   {}   {}   {}   {}   {}   78   {}   61   {}   59   77   {}   74   {}   27   {}   {}   39   67   {}   54   85   74   90   7   61   90   62   {}   93   {}   {}   {}   {}   23   {}   74   93   {}   23   29   3   1   41   {}   65   33   2   98   86   89   25   76   {}   40   38   15   {}   {}   74   97   81   40   16   99   76   96   32   80   86   59   2   99   84   84   39   65   27   76   78   84   16   2   96   59   16   41   28   13   89   22   4   42   91   41   33   87   55   81   29   36   28   6   47   97   97   85   33   41   93   15   85   89   98   98   43   23   73   4   56   29   89   46   65   38   59   68   47   9   93   9   23   39   16   93   98   74   65   75   15   56   93   12   2   81   2   23   97   47   91   15   93   35   16   63   8   53   91   33}

do_execsql_test 1.5.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   81   {}   {}   {}   {}   {}   {}   21   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   12   {}   {}   {}   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   73   {}   23   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   15   {}   {}   {}   {}   {}   {}   55   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   29   29   {}   {}   {}}

do_execsql_test 1.5.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   2   2   2   3   3   3   3   4   4   4   5   5   5   6   7   7   7   7   7   7   7   8   8   8   8   8   8   8   9   9   10   11   11   11   11   12   12   12   12   12   13   13   13   13   13   14   15   15   15   15   15   15   15   15   16   16   16   16   16   16   16   16   16   16   17   17   19   19   19   19   20   20   21   21   21   21   21   22   22   22   22   23   23   23   23   23   25   25   26   26   26   26   26   27   27   28   29   29   29   29   30   30   30   30   30   30   30   30   31   31   31   31   31   32   32   33   33   33   33   33   33   33   33   34   34   34   34   35   35   35   36   36   36   36   36   36   36   36   36   36   36   36   37   37   37   37   38   38   38   39   39   39   39   39   40   40   40   40   41   41   41   41   41   41   42   43   43   43   43   43   43   44   44   44   44   44   46   46   46   46   47   47   47   47   47   47   47   47   47   47   49   49   49}

do_execsql_test 1.5.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.5.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING ) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   90   1   30   {}   {}   {}   {}   30   {}   {}   {}   1   40   {}   50   11   81   {}   40   {}   50   81   40   {}   {}   50   {}   {}   {}   41   81   {}   41   {}   2   30   2   81   82   {}   {}   10   {}   {}   81   {}   41   10   81   30   81   {}   {}   3   23   {}   3   61   80   {}   {}   3   91   91   72   3   63   30   91   94   94   72   91   73   91   84   84   33   41   1   33   84   73   73   91   20   41   84   33   33   84   33   41   84   21   44   22   90   22   81   81   74   93   93   93   81   21   83   44   44   21   21   21   13   21   21   34   11   34   73   74   2   60   2   34   2   34   74   60   23   2   2   2   11   91   60   62   73   74   70   51   65   74   93   65   70   34   70   93   93   93   62   35   44   43   12   35   41   43   44   44   41   80   54   72   43   41   43   91   12   80   80   35   33   12}

do_execsql_test 1.5.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.6.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   0   74   74   74   74   99   99   99   33   89   89   96   96   96   68   68   68   91   91   91   99   99   99   97   78   78   97   97   97   67   93   93   93   84   77   23   93   93   93   65   47   86   86   86   91   91   91   85   85   85   59   59   56   56   91   91   91   90   90   55   89   89   89   47   56   56   56   56   56   75   75   89   98   98   98   81   94   94   94   78   78   78   53   63   63   87   87   87   84   84   84   72   61   73   95   95   95   65   96   98   98   98   74   74   74   65   73   73   73   87   87   87   41   20   31   31   31   95   95   95   79   88   88   88   34   49   49   90   90   96   96   96   75   77   77   77   44   85   85   85   74   74   70   70   59   39   39   47   80   90   90   90   58   58   72   72   72   72   93   93   93   81   81   81   37   37   37   14   62   91   91   91   91   91   34   36   99   99   99   95   95   69   58   52   84   84   84   84   84   39   44   58   58   58   38   83   83   83}

do_execsql_test 1.6.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   0   0   0   41   23   23   23   26   2   2   2   81   59   38   38   38   39   39   46   6   6   6   27   27   27   46   54   8   8   8   29   29   77   23   16   16   16   16   35   35   7   7   7   61   61   61   24   24   24   43   12   12   12   3   3   3   22   22   15   15   15   25   25   1   1   1   40   40   16   16   16   36   36   76   76   4   4   4   30   30   30   29   29   29   2   2   2   37   37   72   41   9   9   9   61   65   13   13   13   58   1   1   1   21   35   5   5   5   11   11   41   12   8   8   8   20   15   15   15   22   22   73   34   8   8   8   11   34   34   59   59   55   55   55   44   2   2   2   7   57   29   29   29   19   19   19   26   26   26   47   36   36   36   9   9   9   66   33   33   33   64   64   9   9   9   13   12   12   12   14   36   36   33   15   15   15   34   3   3   3   58   52   30   30   30   10   10   10   21   21   21   39   30   30   30   34   27   27}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.6.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.6.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276}

do_execsql_test 1.6.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.6.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   89   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   53   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   77   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.6.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   22   {}   {}   {}   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.6.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   {}   {}   1   2   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.6.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.6.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING ) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   91   {}   {}   {}   {}   {}   22   {}   {}   {}   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.6.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 PRECEDING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.7.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   74   74   74   74   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.7.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.7.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.7.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.7.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.7.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   41   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   2   {}   29   {}   {}   {}   46   62   62   {}   {}   16   {}   33   {}   {}   {}   {}   {}   78   {}   61   {}   59   77   {}   74   {}   27   {}   22   39   67   {}   54   85   74   90   7   61   90   62   {}   93   {}   {}   {}   {}   23   {}   74   93   30   23   29   3   1   41   {}   65   33   2   98   86   89   25   76   {}   40   38   15   13   96   74   97   81   40   16   99   76   96   32   80   86   59   2   99   84   84   39   65   27   76   78   84   16   2   96   59   16   41   28   13   89   22   4   42   91   41   33   87   55   81   29   36   28   6   47   97   97   85   33   41   93   15   85   89   98   98   43   23   73   4   56   29   89   46   65   38   59   68   47   9   93   9   23   39   16   93   98   74   65   75   15   56   93   12   2   81   2   23   97   47   91   15   93   35   16   63   8   53   91   33}

do_execsql_test 1.7.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   81   {}   21   {}   {}   {}   {}   21   {}   {}   {}   21   {}   {}   {}   {}   {}   {}   12   {}   {}   {}   12   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   23   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   73   {}   23   {}   {}   {}   {}   {}   {}   {}   {}   74   {}   {}   {}   {}   {}   {}   {}   {}   64   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   15   {}   {}   {}   {}   {}   {}   55   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   27   47   {}   {}   {}   {}   {}   {}   {}   {}   {}   98   {}   98   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   29   {}   {}   {}   {}   {}   {}   {}   29   29   {}   {}   {}}

do_execsql_test 1.7.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   1   1   1   1   1   2   2   2   2   3   3   3   3   4   4   4   5   5   5   6   7   7   7   7   7   7   7   8   8   8   8   8   8   8   9   9   10   11   11   11   11   12   12   12   12   12   13   13   13   13   13   14   15   15   15   15   15   15   15   15   16   16   16   16   16   16   16   16   16   16   17   17   19   19   19   19   20   20   21   21   21   21   21   22   22   22   22   23   23   23   23   23   25   25   26   26   26   26   26   27   27   28   29   29   29   29   30   30   30   30   30   30   30   30   31   31   31   31   31   32   32   33   33   33   33   33   33   33   33   34   34   34   34   35   35   35   36   36   36   36   36   36   36   36   36   36   36   36   37   37   37   37   38   38   38   39   39   39   39   39   40   40   40   40   41   41   41   41   41   41   42   43   43   43   43   43   43   44   44   44   44   44   46   46   46   46   47   47   47   47   47   47   47   47   47   47   49   49   49}

do_execsql_test 1.7.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.7.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   90   1   30   {}   {}   {}   31   30   {}   {}   {}   1   40   {}   50   11   81   42   40   {}   50   81   40   {}   {}   50   {}   52   {}   41   81   {}   41   {}   2   30   2   81   82   53   {}   10   {}   {}   81   {}   41   10   81   30   81   {}   3   3   23   {}   3   61   80   {}   94   3   91   91   72   3   63   30   91   94   94   72   91   73   91   84   84   33   41   1   33   84   73   73   91   20   41   84   33   33   84   33   41   84   21   44   22   90   22   81   81   74   93   93   93   81   21   83   44   44   21   21   21   13   21   21   34   11   34   73   74   2   60   2   34   2   34   74   60   23   2   2   2   11   91   60   62   73   74   70   51   65   74   93   65   70   34   70   93   93   93   62   35   44   43   12   35   41   43   44   44   41   80   54   72   43   41   43   91   12   80   80   35   33   12}

do_execsql_test 1.7.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.8.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {0   74   74   74   74   99   99   99   99   99   89   96   96   96   96   96   68   91   91   91   99   99   99   99   99   97   97   97   97   97   97   93   93   93   93   84   93   93   93   93   93   86   86   86   91   91   91   91   91   85   85   85   59   59   91   91   91   91   91   90   90   89   89   89   89   56   56   56   56   75   75   89   98   98   98   98   98   94   94   94   94   78   78   78   63   87   87   87   87   87   84   84   84   73   95   95   95   95   96   98   98   98   98   98   74   74   74   73   73   87   87   87   87   87   41   31   31   95   95   95   95   95   88   88   88   88   49   90   90   96   96   96   96   96   77   77   77   85   85   85   85   85   74   74   70   70   59   47   80   90   90   90   90   90   72   72   72   72   93   93   93   93   93   81   81   81   37   37   62   91   91   91   91   91   91   91   99   99   99   99   99   95   95   69   84   84   84   84   84   84   84   58   58   58   58   83   83   83   83   83}

do_execsql_test 1.8.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {0   0   0   0   0   23   23   23   2   2   2   2   2   38   38   38   38   38   39   6   6   6   6   6   27   27   27   8   8   8   8   8   29   23   16   16   16   16   16   16   7   7   7   7   7   61   24   24   24   24   12   12   12   3   3   3   3   3   15   15   15   15   15   1   1   1   1   1   16   16   16   16   16   36   36   4   4   4   4   4   30   29   29   29   2   2   2   2   2   37   37   9   9   9   9   9   13   13   13   13   1   1   1   1   1   5   5   5   5   5   11   11   8   8   8   8   8   15   15   15   15   22   22   8   8   8   8   8   11   34   34   55   55   55   44   2   2   2   2   2   7   29   29   19   19   19   19   19   26   26   26   36   36   9   9   9   9   9   33   33   33   33   9   9   9   9   9   12   12   12   12   14   33   15   15   15   15   3   3   3   3   3   30   30   30   10   10   10   10   10   21   21   21   30   30   30   27   27   17   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.8.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.8.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.8.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.8.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   56   {}   {}   {}   {}   {}   {}   {}   {}   {}   89   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   4   {}   {}   {}   {}   {}   {}   {}   {}   53   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   77   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   99   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.8.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   22   {}   {}   {}   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   43   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   33   {}   {}   {}   {}   {}   {}   {}   {}   4   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.8.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {0   1   1   1   1   2   2   3   4   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.8.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.8.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   91   {}   {}   {}   {}   {}   22   {}   {}   {}   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   43   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   33   {}   {}   {}   {}   {}   {}   {}   {}   4   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.8.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.9.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   74   41   74   23   99   26   33   2   89   81   96   59   38   68   39   62   91   46   6   99   97   27   46   78   54   97   8   67   29   93   84   77   23   16   16   93   65   35   47   7   86   74   61   91   85   24   85   43   59   12   32   56   3   91   22   90   55   15   28   89   25   47   1   56   40   43   56   16   75   36   89   98   76   81   4   94   42   30   78   33   29   53   63   2   87   37   80   84   72   41   9   61   73   95   65   13   58   96   98   1   21   74   65   35   5   73   11   51   87   41   12   8   20   31   31   15   95   22   73   79   88   34   8   11   49   34   90   59   96   60   55   75   77   44   2   7   85   57   74   29   70   59   19   39   26   26   47   80   90   36   58   47   9   72   72   66   33   93   75   64   81   9   23   37   13   12   14   62   91   36   91   33   15   34   36   99   3   95   69   58   52   30   50   84   10   84   33   21   39   44   58   30   38   34   83   27   82   17   7}

do_execsql_test 1.9.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   74   41   74   23   99   26   33   2   89   81   96   59   38   68   39   62   91   46   6   99   97   27   46   78   54   97   8   67   29   93   84   77   23   16   16   93   65   35   47   7   86   74   61   91   85   24   85   43   59   12   32   56   3   91   22   90   55   15   28   89   25   47   1   56   40   43   56   16   75   36   89   98   76   81   4   94   42   30   78   33   29   53   63   2   87   37   80   84   72   41   9   61   73   95   65   13   58   96   98   1   21   74   65   35   5   73   11   51   87   41   12   8   20   31   31   15   95   22   73   79   88   34   8   11   49   34   90   59   96   60   55   75   77   44   2   7   85   57   74   29   70   59   19   39   26   26   47   80   90   36   58   47   9   72   72   66   33   93   75   64   81   9   23   37   13   12   14   62   91   36   91   33   15   34   36   99   3   95   69   58   52   30   50   84   10   84   33   21   39   44   58   30   38   34   83   27   82   17   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.9.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.9.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {1   147   106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229}

do_execsql_test 1.9.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.9.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.9.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.9.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.9.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.9.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND CURRENT ROW ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.9.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND CURRENT ROW) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.10.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {74   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.10.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.10.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.10.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229   229   229   229   229}

do_execsql_test 1.10.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.10.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   41   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   2   {}   29   {}   {}   {}   46   62   62   {}   {}   16   {}   33   {}   {}   {}   {}   {}   78   {}   61   {}   59   77   90   74   {}   27   {}   22   39   67   {}   54   85   74   90   7   61   90   62   {}   93   {}   {}   94   {}   23   {}   74   93   30   23   29   3   1   41   80   65   33   2   98   86   89   25   76   65   40   38   15   13   96   74   97   81   40   16   99   76   96   32   80   86   59   2   99   84   84   39   65   27   76   78   84   16   2   96   59   16   41   28   13   89   22   4   42   91   41   33   87   55   81   29   36   28   6   47   97   97   85   33   41   93   15   85   89   98   98   43   23   73   4   56   29   89   46   65   38   59   68   47   9   93   9   23   39   16   93   98   74   65   75   15   56   93   12   2   81   2   23   97   47   91   15   93   35   16   63   8   53   91   33}

do_execsql_test 1.10.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   81   {}   21   {}   {}   {}   {}   21   {}   {}   {}   21   12   {}   {}   {}   {}   {}   12   {}   72   {}   12   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   23   {}   {}   {}   {}   {}   73   {}   {}   {}   {}   {}   73   {}   23   {}   {}   {}   {}   {}   {}   {}   {}   74   {}   {}   {}   {}   {}   {}   {}   {}   64   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   15   55   {}   {}   {}   {}   {}   55   {}   {}   {}   {}   16   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   27   47   {}   {}   {}   {}   {}   {}   {}   {}   {}   98   {}   98   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   29   {}   {}   {}   {}   {}   9   {}   29   29   {}   {}   {}}

do_execsql_test 1.10.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {0   1   1   1   1   1   2   2   2   2   3   3   3   3   4   4   4   5   5   5   6   7   7   7   7   7   7   7   8   8   8   8   8   8   8   9   9   10   11   11   11   11   12   12   12   12   12   13   13   13   13   13   14   15   15   15   15   15   15   15   15   16   16   16   16   16   16   16   16   16   16   17   17   19   19   19   19   20   20   21   21   21   21   21   22   22   22   22   23   23   23   23   23   25   25   26   26   26   26   26   27   27   28   29   29   29   29   30   30   30   30   30   30   30   30   31   31   31   31   31   32   32   33   33   33   33   33   33   33   33   34   34   34   34   35   35   35   36   36   36   36   36   36   36   36   36   36   36   36   37   37   37   37   38   38   38   39   39   39   39   39   40   40   40   40   41   41   41   41   41   41   42   43   43   43   43   43   43   44   44   44   44   44   46   46   46   46   47   47   47   47   47   47   47   47   47   47   49   49   49}

do_execsql_test 1.10.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   1   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   2   2   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   13   13   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.10.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   90   1   30   {}   {}   31   31   30   {}   {}   {}   1   40   {}   50   11   81   42   40   {}   50   81   40   {}   {}   50   {}   52   {}   41   81   {}   41   {}   2   30   2   81   82   53   {}   10   {}   {}   81   {}   41   10   81   30   81   {}   3   3   23   94   3   61   80   {}   94   3   91   91   72   3   63   30   91   94   94   72   91   73   91   84   84   33   41   1   33   84   73   73   91   20   41   84   33   33   84   33   41   84   21   44   22   90   22   81   81   74   93   93   93   81   21   83   44   44   21   21   21   13   21   21   34   11   34   73   74   2   60   2   34   2   34   74   60   23   2   2   2   11   91   60   62   73   74   70   51   65   74   93   65   70   34   70   93   93   93   62   35   44   43   12   35   41   43   44   44   41   80   54   72   43   41   43   91   12   80   80   35   33   12}

do_execsql_test 1.10.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND 4 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.11.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {74   74   74   99   99   99   99   99   99   99   96   96   96   96   96   96   91   91   99   99   99   99   99   99   99   97   97   97   97   97   97   93   93   93   93   93   93   93   93   93   93   86   91   91   91   91   91   91   91   85   85   85   91   91   91   91   91   91   91   90   90   89   89   89   89   56   56   75   75   89   98   98   98   98   98   98   98   94   94   94   94   78   78   87   87   87   87   87   87   87   84   84   95   95   95   95   96   98   98   98   98   98   98   98   74   74   74   87   87   87   87   87   87   87   41   95   95   95   95   95   95   95   88   88   88   90   90   96   96   96   96   96   96   96   77   85   85   85   85   85   85   85   74   74   70   70   80   90   90   90   90   90   90   90   72   72   93   93   93   93   93   93   93   81   81   81   62   91   91   91   91   91   91   91   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   58   58   83   83   83   83   83   83   83}

do_execsql_test 1.11.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {0   0   0   0   0   23   2   2   2   2   2   2   2   38   38   38   38   6   6   6   6   6   6   6   27   8   8   8   8   8   8   8   16   16   16   16   16   16   7   7   7   7   7   7   7   24   24   24   12   12   12   3   3   3   3   3   3   3   15   15   15   1   1   1   1   1   1   1   16   16   16   16   16   4   4   4   4   4   4   4   29   29   2   2   2   2   2   2   2   9   9   9   9   9   9   9   13   13   1   1   1   1   1   1   1   5   5   5   5   5   8   8   8   8   8   8   8   15   15   15   15   8   8   8   8   8   8   8   11   34   34   55   44   2   2   2   2   2   2   2   7   19   19   19   19   19   19   19   26   26   26   9   9   9   9   9   9   9   33   33   9   9   9   9   9   9   9   12   12   12   12   14   15   15   15   3   3   3   3   3   3   3   30   10   10   10   10   10   10   10   21   21   21   30   27   27   17   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.11.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.11.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {106   109   168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229   229   229}

do_execsql_test 1.11.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.11.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   97   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   56   {}   {}   {}   {}   {}   {}   {}   {}   {}   89   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   4   {}   {}   {}   {}   {}   {}   {}   {}   53   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   {}   {}   {}   {}   73   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   77   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   99   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.11.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   12   {}   {}   {}   {}   {}   22   {}   {}   {}   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   43   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   33   {}   {}   {}   {}   {}   {}   {}   {}   4   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   15   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.11.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {0   1   1   1   1   2   2   3   4   6   7   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.11.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   1   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   2   2   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   13   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.11.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   91   {}   {}   {}   {}   {}   22   {}   {}   {}   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   43   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   33   {}   {}   {}   {}   {}   {}   {}   {}   4   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   15   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   16   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.11.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND 2 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.12.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {74   99   99   99   99   99   89   96   96   96   96   96   68   91   91   91   99   99   99   99   99   97   97   97   97   97   97   93   93   93   93   84   93   93   93   93   93   86   86   86   91   91   91   91   91   85   85   85   59   59   91   91   91   91   91   90   90   89   89   89   89   56   56   56   56   75   75   89   98   98   98   98   98   94   94   94   94   78   78   78   63   87   87   87   87   87   84   84   84   73   95   95   95   95   96   98   98   98   98   98   74   74   74   73   73   87   87   87   87   87   41   31   31   95   95   95   95   95   88   88   88   88   49   90   90   96   96   96   96   96   77   77   77   85   85   85   85   85   74   74   70   70   59   47   80   90   90   90   90   90   72   72   72   72   93   93   93   93   93   81   81   81   37   37   62   91   91   91   91   91   91   91   99   99   99   99   99   95   95   69   84   84   84   84   84   84   84   58   58   58   58   83   83   83   83   83   82   82   17   7}

do_execsql_test 1.12.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {0   23   23   23   2   2   2   2   2   38   38   38   38   38   39   6   6   6   6   6   27   27   27   8   8   8   8   8   29   23   16   16   16   16   16   16   7   7   7   7   7   61   24   24   24   24   12   12   12   3   3   3   3   3   15   15   15   15   15   1   1   1   1   1   16   16   16   16   16   36   36   4   4   4   4   4   30   29   29   29   2   2   2   2   2   37   37   9   9   9   9   9   13   13   13   13   1   1   1   1   1   5   5   5   5   5   11   11   8   8   8   8   8   15   15   15   15   22   22   8   8   8   8   8   11   34   34   55   55   55   44   2   2   2   2   2   7   29   29   19   19   19   19   19   26   26   26   36   36   9   9   9   9   9   33   33   33   33   9   9   9   9   9   12   12   12   12   14   33   15   15   15   15   3   3   3   3   3   30   30   30   10   10   10   10   10   21   21   21   30   30   30   27   27   17   7   7   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.12.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.12.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229   229   229   229   229}

do_execsql_test 1.12.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.12.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   {}   {}   56   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   78   {}   {}   {}   {}   {}   {}   {}   {}   37   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   21   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   85   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.12.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   21   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   12   {}   {}   {}   {}   {}   12   {}   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   53   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.12.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {0   1   2   2   3   3   5   6   7   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.12.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   11   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   12   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   13   23   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.12.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING ) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   21   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   12   {}   {}   {}   {}   {}   12   {}   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   53   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   74   {}   {}   {}   {}   {}   {}   {}   {}   34   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.12.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND 4 FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.13.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {74   99   99   99   33   89   89   96   96   96   68   68   68   91   91   91   99   99   99   97   78   78   97   97   97   67   93   93   93   84   77   23   93   93   93   65   47   86   86   86   91   91   91   85   85   85   59   59   56   56   91   91   91   90   90   55   89   89   89   47   56   56   56   56   56   75   75   89   98   98   98   81   94   94   94   78   78   78   53   63   63   87   87   87   84   84   84   72   61   73   95   95   95   65   96   98   98   98   74   74   74   65   73   73   73   87   87   87   41   20   31   31   31   95   95   95   79   88   88   88   34   49   49   90   90   96   96   96   75   77   77   77   44   85   85   85   74   74   70   70   59   39   39   47   80   90   90   90   58   58   72   72   72   72   93   93   93   81   81   81   37   37   37   14   62   91   91   91   91   91   34   36   99   99   99   95   95   69   58   52   84   84   84   84   84   39   44   58   58   58   38   83   83   83   82   82   17   7   {}   {}}

do_execsql_test 1.13.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {23   23   23   26   2   2   2   81   59   38   38   38   39   39   46   6   6   6   27   27   27   46   54   8   8   8   29   29   77   23   16   16   16   16   35   35   7   7   7   61   61   61   24   24   24   43   12   12   12   3   3   3   22   22   15   15   15   25   25   1   1   1   40   40   16   16   16   36   36   76   76   4   4   4   30   30   30   29   29   29   2   2   2   37   37   72   41   9   9   9   61   65   13   13   13   58   1   1   1   21   35   5   5   5   11   11   41   12   8   8   8   20   15   15   15   22   22   73   34   8   8   8   11   34   34   59   59   55   55   55   44   2   2   2   7   57   29   29   29   19   19   19   26   26   26   47   36   36   36   9   9   9   66   33   33   33   64   64   9   9   9   13   12   12   12   14   36   36   33   15   15   15   34   3   3   3   58   52   30   30   30   10   10   10   21   21   21   39   30   30   30   34   27   27   17   7   7   7   {}   {}}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.13.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.13.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {168   134   218   191   212   229   240   213   234   196   223   44   92   109   105   136   146   65   156   132   154   102   123   119   160   152   146   147   136   243   261   263   210   11   79   63   84   78   120   87   162   124   141   138   227   228   179   231   234   280   28   41   124   57   130   92   57   110   114   136   147   167   110   180   193   191   252   187   179   206   181   221   279   76   78   80   116   117   71   80   171   173   177   157   161   179   214   225   182   209   269   271   235   229   103   74   131   133   113   74   87   145   190   161   169   140   111   132   213   187   208   223   235   189   274   33   108   65   26   70   51   52   128   109   121   124   85   107   150   195   226   172   173   187   223   207   212   119   50   124   96   110   87   48   110   173   124   197   211   144   196   195   200   202   224   216   207   52   83   103   36   88   171   158   156   198   121   210   132   210   239   250   232   105   99   72   55   120   59   109   150   161   111   101   200   175   188   170   202   163   184   163   172   276   249   229   229   229   {}   {}}

do_execsql_test 1.13.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.13.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING) FROM t2
} {41   {}   {}   {}   {}   {}   {}   {}   59   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   43   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   84   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   65   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   74   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.13.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING) FROM t2
} {40   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   51   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   22   {}   {}   {}   {}   {}   2   {}   {}   {}   62   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.13.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {1   2   2   3   4   5   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.13.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {20   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   11   21   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   12   12   22   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.13.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING ) FROM t2
} {40   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   51   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   22   {}   {}   {}   {}   {}   2   {}   {}   {}   62   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.13.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 2 FOLLOWING    AND 4 FOLLOWING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.14.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99}

do_execsql_test 1.14.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.14.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.14.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.14.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.14.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {0   81   86   81   46   98   97   23   41   72   29   13   28   35   16   47   47   9   24   26   98   58   8   24   30   91   58   2   56   29   73   2   42   46   62   62   73   40   16   85   33   37   81   25   9   87   78   87   61   28   59   77   90   74   9   27   41   22   39   67   72   54   85   74   90   7   61   90   62   4   93   72   96   94   29   23   95   74   93   30   23   29   3   1   41   80   65   33   2   98   86   89   25   76   65   40   38   15   13   96   74   97   81   40   16   99   76   96   32   80   86   59   2   99   84   84   39   65   27   76   78   84   16   2   96   59   16   41   28   13   89   22   4   42   91   41   33   87   55   81   29   36   28   6   47   97   97   85   33   41   93   15   85   89   98   98   43   23   73   4   56   29   89   46   65   38   59   68   47   9   93   9   23   39   16   93   98   74   65   75   15   56   93   12   2   81   2   23   97   47   91   15   93   35   16   63   8   53   91   33}

do_execsql_test 1.14.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   90   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   81   21   21   {}   {}   {}   {}   21   {}   {}   {}   21   12   {}   72   {}   {}   {}   12   {}   72   {}   12   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   23   {}   {}   {}   {}   {}   73   {}   {}   {}   {}   {}   73   {}   23   {}   {}   {}   {}   {}   {}   {}   {}   74   {}   {}   {}   {}   {}   {}   {}   {}   64   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   55   {}   {}   {}   {}   {}   {}   15   55   {}   {}   {}   {}   {}   55   {}   {}   {}   {}   16   {}   26   26   {}   {}   {}   {}   26   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   27   47   {}   {}   {}   98   {}   {}   {}   {}   {}   98   {}   98   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   29   {}   {}   {}   {}   {}   9   {}   29   29   {}   {}   {}}

do_execsql_test 1.14.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   1   1   1   1   2   2   2   2   3   3   3   3   4   4   4   5   5   5   6   7   7   7   7   7   7   7   8   8   8   8   8   8   8   9   9   10   11   11   11   11   12   12   12   12   12   13   13   13   13   13   14   15   15   15   15   15   15   15   15   16   16   16   16   16   16   16   16   16   16   17   17   19   19   19   19   20   20   21   21   21   21   21   22   22   22   22   23   23   23   23   23   25   25   26   26   26   26   26   27   27   28   29   29   29   29   30   30   30   30   30   30   30   30   31   31   31   31   31   32   32   33   33   33   33   33   33   33   33   34   34   34   34   35   35   35   36   36   36   36   36   36   36   36   36   36   36   36   37   37   37   37   38   38   38   39   39   39   39   39   40   40   40   40   41   41   41   41   41   41   42   43   43   43   43   43   43   44   44   44   44   44   46   46   46   46   47   47   47   47   47   47   47   47   47   47   49   49   49}

do_execsql_test 1.14.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   80   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   1   51   51   91   91   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   2   2   62   62   62   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   13   13   43   43   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   74   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   35   85   85   85   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   66   66   66   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   37   37   37   87   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   58   58   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   39   39   39   89   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.14.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FROM t2
} {0   74   32   31   84   91   74   3   93   84   74   31   12   90   31   22   74   64   43   64   64   90   74   22   43   90   1   30   62   22   31   31   30   74   64   64   1   40   33   50   11   81   42   40   13   50   81   40   13   13   50   33   52   24   41   81   34   41   34   2   30   2   81   82   53   33   10   33   33   81   34   41   10   81   30   81   4   3   3   23   94   3   61   80   84   94   3   91   91   72   3   63   30   91   94   94   72   91   73   91   84   84   33   41   1   33   84   73   73   91   20   41   84   33   33   84   33   41   84   21   44   22   90   22   81   81   74   93   93   93   81   21   83   44   44   21   21   21   13   21   21   34   11   34   73   74   2   60   2   34   2   34   74   60   23   2   2   2   11   91   60   62   73   74   70   51   65   74   93   65   70   34   70   93   93   93   62   35   44   43   12   35   41   43   44   44   41   80   54   72   43   41   43   91   12   80   80   35   33   12}

do_execsql_test 1.14.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.15.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   83   83   83   83   83   83   83   83   83}

do_execsql_test 1.15.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {0   0   0   0   0   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.15.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.15.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.15.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.15.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING) FROM t2
} {0   81   86   81   46   1   67   93   26   95   80   65   56   85   30   12   81   35   89   97   31   31   85   40   96   4   73   84   9   91   73   12   5   56   24   85   49   96   75   53   61   8   8   1   55   34   43   59   80   35   15   78   35   56   70   76   59   51   75   63   26   53   5   89   15   21   5   73   33   29   74   66   12   26   58   4   12   31   35   9   87   73   55   59   53   62   73   23   62   33   90   13   90   9   10   66   5   58   44   38   58   22   33   37   2   73   36   31   72   30   47   73   15   96   70   59   90   {}   7   21   83   {}   47   90   55   36   66   {}   50   {}   84   30   {}   {}   34   77   74   {}   58   {}   13   {}   82   93   69   14   62   44   {}   {}   30   {}   83   93   {}   {}   {}   84   {}   {}   {}   {}   14   30   82   34   34   3   {}   {}   {}   {}   {}   84   {}   {}   {}   99   {}   {}   {}   {}   {}   {}   {}   58   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.15.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   61   {}   {}   {}   81   {}   91   {}   {}   {}   {}   {}   {}   {}   {}   {}   12   {}   72   {}   {}   {}   22   {}   82   {}   12   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   43   {}   {}   {}   {}   {}   33   {}   {}   {}   {}   {}   {}   {}   33   {}   {}   {}   {}   {}   {}   {}   {}   4   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   75   {}   {}   {}   {}   {}   {}   15   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   16   {}   26   36   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   37   {}   {}   {}   {}   {}   47   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   98   {}   {}   {}   {}   {}   58   {}   38   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   59   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.15.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   1   1   1   2   2   3   4   6   7   8   8   8   9   9   10   11   12   12   13   14   15   15   16   16   17   19   21   22   22   23   23   24   25   26   27   29   29   30   30   31   32   33   33   33   34   34   34   35   36   36   36   37   38   38   39   39   40   41   41   43   44   44   46   46   47   47   47   49   50   52   53   55   55   56   56   57   58   58   58   59   59   59   61   62   62   63   65   65   66   68   69   72   72   73   73   74   74   74   75   76   77   78   80   81   81   82   83   84   84   85   85   85   86   87   88   89   89   90   90   91   91   91   93   93   95   95   95   96   97   98   99   99   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.15.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {0   80   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   1   51   51   91   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   2   2   62   62   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   13   13   43   43   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   74   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   35   85   85   85   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   66   66   66   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   37   37   37   87   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   58   58   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   39   39   39   89   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.15.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING ) FROM t2
} {0   74   32   31   84   1   14   53   3   84   44   2   93   91   32   52   34   25   33   95   65   61   35   3   74   81   2   91   33   13   23   93   12   5   46   6   82   91   44   2   73   43   84   22   95   82   63   12   75   15   93   35   85   36   33   94   77   83   7   65   43   85   64   95   46   96   33   26   36   65   17   74   74   55   33   25   47   7   47   56   7   87   55   4   58   28   47   15   95   56   7   87   55   46   58   58   26   56   17   16   99   29   7   75   16   38   99   58   98   36   15   6   {}   8   89   9   9   56   {}   97   {}   78   16   28   26   36   {}   59   39   99   27   78   {}   {}   {}   37   27   98   {}   88   8   {}   28   {}   {}   {}   49   37   29   {}   59   {}   {}   47   {}   69   39   59   99   8   78   9   {}   {}   58   49   {}   {}   {}   {}   58   {}   38   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   59   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.15.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 PRECEDING    AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.16.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   83   83   83   83   83   83   83   83   83   82   82   17   7}

do_execsql_test 1.16.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.16.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.16.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229}

do_execsql_test 1.16.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {1   76   78   33   11   108   52   83   79   65   26   70   103   80   36   116   51   52   128   117   71   63   84   109   78   147   88   121   106   124   85   107   171   150   80   171   120   109   158   87   168   173   162   156   195   198   177   124   121   134   141   210   157   132   161   218   226   191   179   138   214   212   172   173   229   240   187   210   227   228   223   225   179   182   231   207   209   212   239   234   213   234   269   196   271   235   250   223   232   229   280   44   28   105   41   99   92   72   55   109   120   119   50   124   96   59   124   110   57   130   103   74   87   48   105   136   131   133   92   109   57   146   113   74   150   87   110   65   110   145   161   156   114   111   136   147   173   124   132   101   154   167   190   161   110   102   123   169   140   111   180   119   160   197   152   146   147   132   213   193   200   136   175   188   187   208   211   144   223   196   170   202   163   184   195   200   163   191   252   235   243   172   187   202   179   261   263   206   189   276   181   274   249   221   210   229   279   224   216   207}

do_execsql_test 1.16.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {0   4   61   42   8   35   77   7   81   96   9   11   89   32   53   91   30   51   56   54   73   22   59   75   74   78   8   16   65   15   8   31   87   90   12   32   96   74   76   37   85   90   15   35   2   60   36   75   9   51   47   63   51   90   26   42   26   8   76   80   90   37   87   56   79   5   87   8   2   39   73   64   36   90   72   78   36   73   51   33   20   41   2   26   37   33   8   14   33   81   55   1   9   12   39   64   87   72   34   82   21   34   99   62   74   41   69   22   75   27   58   8   79   77   26   26   55   {}   29   30   7   {}   66   55   2   34   64   {}   33   {}   44   84   {}   {}   95   85   19   {}   83   {}   91   {}   {}   9   50   91   33   34   {}   {}   84   {}   7   9   {}   {}   {}   44   {}   {}   {}   {}   91   84   {}   95   95   52   {}   {}   {}   {}   {}   21   {}   {}   {}   58   {}   {}   {}   {}   {}   {}   {}   83   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.16.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   81   {}   {}   {}   21   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   12   {}   62   {}   {}   {}   12   {}   {}   {}   72   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   53   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   95   {}   {}   {}   {}   {}   {}   85   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   56   {}   36   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   57   {}   {}   {}   {}   {}   7   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   8   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   9   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.16.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   1   2   2   3   3   5   6   7   8   8   9   9   10   11   12   12   13   13   14   15   16   16   17   19   20   21   22   23   23   24   25   26   26   27   28   29   30   31   31   33   33   33   33   34   34   35   36   36   36   37   37   38   39   39   40   41   41   42   43   44   46   47   47   47   47   49   51   52   53   54   55   56   56   57   58   58   58   59   59   59   61   61   62   63   65   65   65   67   69   70   72   72   73   74   74   74   74   75   76   77   78   80   81   81   83   84   84   84   85   85   87   87   88   89   89   90   90   90   91   91   91   93   93   95   95   96   96   97   98   99   99   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.16.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   80   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   1   11   61   81   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   12   12   72   82   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   13   23   63   73   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   34   74   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   35   85   85   95   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   26   76   86   96   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   37   47   47   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   58   58   68   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   39   49   59   99   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.16.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING ) FROM t2
} {0   64   42   81   94   1   44   73   74   44   85   22   33   41   72   93   34   65   54   5   15   81   15   63   84   21   2   62   54   93   43   33   2   75   16   86   23   12   85   62   13   53   94   12   75   23   73   72   96   46   33   55   25   26   74   34   87   84   87   55   53   25   84   75   56   66   54   36   97   55   78   84   84   95   74   65   17   87   77   96   8   47   95   34   89   98   7   46   6   96   8   47   95   56   89   59   36   36   78   96   89   29   37   95   56   39   {}   8   58   67   85   86   {}   58   49   {}   29   76   {}   77   {}   78   56   98   36   97   {}   59   89   89   47   78   {}   {}   {}   38   68   58   {}   58   38   {}   98   {}   {}   {}   19   57   9   {}   9   {}   {}   7   {}   {}   {}   39   89   38   78   39   {}   {}   8   19   {}   {}   {}   {}   89   {}   39   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   9   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.16.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN CURRENT ROW         AND UNBOUNDED FOLLOWING) FROM t2
} {0   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.17.2.1 {
  SELECT max(b) OVER ( ORDER BY a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   99   95   95   84   84   84   84   84   84   84   84   83   83   83   83   83   83   83   83   83   82   82   17   7   {}   {}   {}   {}}

do_execsql_test 1.17.2.2 {
  SELECT min(b) OVER ( ORDER BY a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   7   {}   {}   {}   {}}
................................................................................
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.27 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.39 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.49 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.71 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.81 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89 0.89}

do_test 1.17.7.6 {
  set myres {}
  foreach r [db eval {SELECT percent_rank() OVER (PARTITION BY b%2 ORDER BY b%10 ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING) FROM t2}] {
    lappend myres [format %.2f [set r]]
  }
  set myres
} {0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.36 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.59 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.42 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.61 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80 0.80}

do_test 1.17.8.1 {
  set myres {}
................................................................................
  SELECT last_value(a+b) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   229   {}   {}   {}   {}}

do_execsql_test 1.17.9.6 {
  SELECT last_value(a+b) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.17.10.1 {
  SELECT nth_value(b,b+1) OVER (ORDER BY a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING) FROM t2
} {23   78   85   29   84   51   93   91   68   74   65   12   4   22   37   15   53   8   16   29   8   34   3   76   73   63   90   47   98   47   90   73   20   89   91   22   77   73   42   41   32   55   79   51   74   44   81   7   65   8   43   80   8   89   90   29   36   15   42   9   9   41   20   16   11   87   20   90   84   80   41   37   34   9   75   63   34   8   8   81   95   31   74   36   41   99   90   91   99   13   2   35   33   36   38   37   20   75   17   {}   5   34   58   33   19   31   50   34   23   {}   72   90   11   85   90   36   2   {}   39   27   {}   {}   64   2   74   95   37   {}   58   {}   34   44   {}   {}   30   70   47   {}   7   {}   15   {}   {}   12   33   36   99   17   {}   {}   44   {}   {}   12   {}   {}   {}   34   {}   {}   {}   {}   36   44   {}   30   30   10   {}   {}   {}   {}   {}   30   {}   {}   {}   84   {}   {}   {}   {}   {}   {}   {}   7   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.17.9.2 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%10 ORDER BY a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING) FROM t2
} {80   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   21   {}   {}   {}   31   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   2   {}   {}   {}   {}   {}   72   {}   {}   {}   82   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   73   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   64   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   76   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   27   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   38   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.17.9.3 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b,a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {2   3   3   5   6   7   7   8   8   9   10   11   12   12   13   13   14   15   15   16   16   19   20   21   22   22   23   23   25   26   26   27   28   29   29   30   31   32   33   33   33   34   34   34   35   36   36   37   37   38   39   39   40   41   41   42   43   44   44   46   47   47   49   50   51   52   53   55   55   56   56   57   58   58   58   59   59   59   60   61   62   63   64   65   65   67   68   69   72   72   73   73   74   74   74   75   75   76   77   78   80   81   81   83   84   84   85   85   86   87   88   89   89   90   90   91   91   91   91   93   93   94   95   95   96   97   98   98   99   99   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.17.9.4 {
  SELECT nth_value(b,b+1) OVER ( PARTITION BY b%10 ORDER BY b,a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {30   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   21   31   91   91   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   22   22   32   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   33   33   83   93   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   44   84   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   65   95   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   36   96   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   47   57   67   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   78   88   98   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   59   59   69   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.17.9.5 {
  SELECT nth_value(b,b+1) OVER ( ORDER BY b%10,a ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING ) FROM t2
} {80   84   22   2   34   41   85   23   24   34   25   12   13   11   72   3   85   95   4   75   85   21   65   73   44   31   62   42   4   3   73   13   2   95   56   16   43   2   25   33   83   73   34   72   96   43   13   82   16   16   13   15   65   36   74   14   7   94   47   95   73   65   35   96   36   27   4   67   77   95   78   65   44   5   74   95   78   47   47   36   58   17   5   64   29   58   8   16   86   36   58   17   5   36   29   59   67   26   78   66   49   59   38   6   96   89   {}   38   99   47   26   16   {}   8   19   {}   9   26   {}   87   {}   88   76   58   67   77   {}   9   79   49   37   88   {}   {}   {}   28   98   99   {}   59   39   {}   58   {}   {}   {}   99   27   39   {}   29   {}   {}   8   {}   {}   {}   69   49   39   88   {}   {}   {}   38   99   {}   {}   {}   {}   29   {}   89   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

do_execsql_test 1.17.9.6 {
  SELECT nth_value(b,b+1) OVER (PARTITION BY b%2,a ORDER BY b%10 ROWS BETWEEN 4 FOLLOWING    AND UNBOUNDED FOLLOWING) FROM t2
} {{}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}   {}}

finish_test

Changes to test/window4.tcl.

22
23
24
25
26
27
28
29





































30

  INSERT INTO t3 VALUES('a'), ('b'), ('c'), ('d'), ('e');
  INSERT INTO t3 VALUES('f'), ('g'), ('h'), ('i'), ('j');
}

for {set i 1} {$i < 20} {incr i} {
  execsql_test 1.$i "SELECT a, ntile($i) OVER (ORDER BY a) FROM t3"
}






































finish_test









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  INSERT INTO t3 VALUES('a'), ('b'), ('c'), ('d'), ('e');
  INSERT INTO t3 VALUES('f'), ('g'), ('h'), ('i'), ('j');
}

for {set i 1} {$i < 20} {incr i} {
  execsql_test 1.$i "SELECT a, ntile($i) OVER (ORDER BY a) FROM t3"
}

execsql_test 2.0 {
  DROP TABLE IF EXISTS t4;
  CREATE TABLE t4(a INTEGER PRIMARY KEY, b TEXT, c INTEGER);
  INSERT INTO t4 VALUES(1, 'A', 9);
  INSERT INTO t4 VALUES(2, 'B', 3);
  INSERT INTO t4 VALUES(3, 'C', 2);
  INSERT INTO t4 VALUES(4, 'D', 10);
  INSERT INTO t4 VALUES(5, 'E', 5);
  INSERT INTO t4 VALUES(6, 'F', 1);
  INSERT INTO t4 VALUES(7, 'G', 1);
  INSERT INTO t4 VALUES(8, 'H', 2);
  INSERT INTO t4 VALUES(9, 'I', 10);
  INSERT INTO t4 VALUES(10, 'J', 4);
}

execsql_test 2.1 {
  SELECT a, nth_value(b, c) OVER (ORDER BY a) FROM t4
}

execsql_test 3.0 {
  DROP TABLE IF EXISTS t5;
  CREATE TABLE t5(a INTEGER PRIMARY KEY, b TEXT, c TEXT, d INTEGER);
  INSERT INTO t5 VALUES(1, 'A', 'one',   5);
  INSERT INTO t5 VALUES(2, 'B', 'two',   4);
  INSERT INTO t5 VALUES(3, 'A', 'three', 3);
  INSERT INTO t5 VALUES(4, 'B', 'four',  2);
  INSERT INTO t5 VALUES(5, 'A', 'five',  1);
}

execsql_test 3.1 {
  SELECT a, nth_value(c, d) OVER (ORDER BY b) FROM t5
}

execsql_test 3.2 {
  SELECT a, nth_value(c, d) OVER (PARTITION BY b ORDER BY a) FROM t5
}

finish_test

Changes to test/window4.test.

98
99
100
101
102
103
104








































105
  SELECT a, ntile(18) OVER (ORDER BY a) FROM t3
} {a 1   b 2   c 3   d 4   e 5   f 6   g 7   h 8   i 9   j 10}

do_execsql_test 1.19 {
  SELECT a, ntile(19) OVER (ORDER BY a) FROM t3
} {a 1   b 2   c 3   d 4   e 5   f 6   g 7   h 8   i 9   j 10}









































finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  SELECT a, ntile(18) OVER (ORDER BY a) FROM t3
} {a 1   b 2   c 3   d 4   e 5   f 6   g 7   h 8   i 9   j 10}

do_execsql_test 1.19 {
  SELECT a, ntile(19) OVER (ORDER BY a) FROM t3
} {a 1   b 2   c 3   d 4   e 5   f 6   g 7   h 8   i 9   j 10}

do_execsql_test 2.0 {
  DROP TABLE IF EXISTS t4;
  CREATE TABLE t4(a INTEGER PRIMARY KEY, b TEXT, c INTEGER);
  INSERT INTO t4 VALUES(1, 'A', 9);
  INSERT INTO t4 VALUES(2, 'B', 3);
  INSERT INTO t4 VALUES(3, 'C', 2);
  INSERT INTO t4 VALUES(4, 'D', 10);
  INSERT INTO t4 VALUES(5, 'E', 5);
  INSERT INTO t4 VALUES(6, 'F', 1);
  INSERT INTO t4 VALUES(7, 'G', 1);
  INSERT INTO t4 VALUES(8, 'H', 2);
  INSERT INTO t4 VALUES(9, 'I', 10);
  INSERT INTO t4 VALUES(10, 'J', 4);
} {}

do_execsql_test 2.1 {
  SELECT a, nth_value(b, c) OVER (ORDER BY a) FROM t4
} {1 {}   2 {}   3 B   4 {}   5 E   6 A   7 A   8 B   9 {}   10 D}

do_execsql_test 3.0 {
  DROP TABLE IF EXISTS t5;
  CREATE TABLE t5(a INTEGER PRIMARY KEY, b TEXT, c TEXT, d INTEGER);
  INSERT INTO t5 VALUES(1, 'A', 'one',   5);
  INSERT INTO t5 VALUES(2, 'B', 'two',   4);
  INSERT INTO t5 VALUES(3, 'A', 'three', 3);
  INSERT INTO t5 VALUES(4, 'B', 'four',  2);
  INSERT INTO t5 VALUES(5, 'A', 'five',  1);
} {}

do_execsql_test 3.1 {
  SELECT a, nth_value(c, d) OVER (ORDER BY b) FROM t5
} {1 {}   3 five   5 one   2 two   4 three}

explain_i {
  SELECT a, nth_value(c, d) OVER (PARTITION BY b ORDER BY a) FROM t5
  }
do_execsql_test 3.2 {
  SELECT a, nth_value(c, d) OVER (PARTITION BY b ORDER BY a) FROM t5
} {1 {}   3 {}   5 one   2 {}   4 four}

finish_test