File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -195,11 +195,30 @@ func queryString(tq *SQuery, tmpFields ...IQueryField) string {
195195 }
196196 if tq .groupBy != nil && len (tq .groupBy ) > 0 {
197197 buf .WriteString (" GROUP BY " )
198- for i , f := range tq .groupBy {
198+ groupByFields := make (map [string ]IQueryField )
199+ for i := range tq .groupBy {
200+ f := tq .groupBy [i ]
201+ if _ , ok := groupByFields [f .Reference ()]; ok {
202+ continue
203+ }
199204 if i > 0 {
200205 buf .WriteString (", " )
201206 }
202207 buf .WriteString (f .Reference ())
208+ groupByFields [f .Reference ()] = f
209+ }
210+ // DAMENG SQL Compatibility, all order by fields should be in group by
211+ for i := range tq .orderBy {
212+ f := tq .orderBy [i ]
213+ if _ , ok := groupByFields [f .field .Reference ()]; ok {
214+ continue
215+ }
216+ if ff , ok := f .field .(IFunctionQueryField ); ok && ff .IsAggregate () {
217+ continue
218+ }
219+ buf .WriteString (", " )
220+ buf .WriteString (f .field .Reference ())
221+ groupByFields [f .field .Reference ()] = f .field
203222 }
204223 }
205224 /*if tq.having != nil {
@@ -208,7 +227,8 @@ func queryString(tq *SQuery, tmpFields ...IQueryField) string {
208227 }*/
209228 if tq .orderBy != nil && len (tq .orderBy ) > 0 {
210229 buf .WriteString (" ORDER BY " )
211- for i , f := range tq .orderBy {
230+ for i := range tq .orderBy {
231+ f := tq .orderBy [i ]
212232 if i > 0 {
213233 buf .WriteString (", " )
214234 }
You can’t perform that action at this time.
0 commit comments