Treat identifiers in the HAVING clause the same as in the WHERE clause.
Only consider AS names from the result set to match if there are no other
matches.  Continuation of the fix for [2500cdb9be05].  This check-in
fixes a bug found by [http://www.sqlite.org/sqllogictest/ | SqlLogicTest]
during release testing for version 3.7.17.

FossilOrigin-Name: 9ffff3d05226bbd01a0745dd0a511776358253c0
diff --git a/src/resolve.c b/src/resolve.c
index a8e1969..91efcaa 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -1159,8 +1159,8 @@
     ** re-evaluated for each reference to it.
     */
     sNC.pEList = p->pEList;
-    if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
     sNC.ncFlags |= NC_AsMaybe;
+    if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
     if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
     sNC.ncFlags &= ~NC_AsMaybe;