Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -4951,11 +4951,11 @@ if( pA->iTable!=pB->iTable && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2; } #ifndef SQLITE_OMIT_WINDOWFUNC /* Justification for the assert(): - /* window functions have p->op==TK_FUNCTION but aggregate functions + ** window functions have p->op==TK_FUNCTION but aggregate functions ** have p->op==TK_AGG_FUNCTION. So any comparison between an aggregate ** function and a window function should have failed before reaching ** this point. And, it is not possible to have a window function and ** a scalar function with the same name and number of arguments. So ** if we reach this point, either A and B both window functions or Index: src/resolve.c ================================================================== --- src/resolve.c +++ src/resolve.c @@ -1243,15 +1243,17 @@ } for(j=0; jpEList->nExpr; j++){ if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){ #ifndef SQLITE_OMIT_WINDOWFUNC if( pE->pWin ){ + /* Since this window function is being changed into a reference + ** to the same window function the result set, remove the instance + ** of this window function from the Select.pWin list. */ Window **pp; for(pp=&pSelect->pWin; *pp; pp=&(*pp)->pNextWin){ if( *pp==pE->pWin ){ *pp = (*pp)->pNextWin; - break; } } } #endif pItem->u.x.iOrderByCol = j+1;