For queries of the form "SELECT p, max(q) FROM t1", the value of column p

returned is the one on the same row that holds the maximum value of q.

FossilOrigin-Name: adb29232b659c5332b6841776372407fcc350b08
This commit is contained in:
drh
2012-02-02 17:35:43 +00:00
parent a451017d62
commit 7a95789c0c
7 changed files with 50 additions and 14 deletions
+10
View File
@@ -28,6 +28,14 @@ static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
return context->pColl;
}
/*
** Indicate that the accumulator load should be skipped on this
** iteration of the aggregate loop.
*/
static void sqlite3SkipAccumulatorLoad(sqlite3_context *context){
context->skipFlag = 1;
}
/*
** Implementation of the non-aggregate min() and max() functions
*/
@@ -1354,6 +1362,8 @@ static void minmaxStep(
cmp = sqlite3MemCompare(pBest, pArg, pColl);
if( (max && cmp<0) || (!max && cmp>0) ){
sqlite3VdbeMemCopy(pBest, pArg);
}else{
sqlite3SkipAccumulatorLoad(context);
}
}else{
sqlite3VdbeMemCopy(pBest, pArg);