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,27 @@ 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 .Name ()]; ok {
202+ continue
203+ }
199204 if i > 0 {
200205 buf .WriteString (", " )
201206 }
202207 buf .WriteString (f .Reference ())
208+ groupByFields [f .Name ()] = 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 .Name ()]; ok {
214+ continue
215+ }
216+ buf .WriteString (", " )
217+ buf .WriteString (f .field .Reference ())
218+ groupByFields [f .field .Name ()] = f .field
203219 }
204220 }
205221 /*if tq.having != nil {
@@ -208,7 +224,8 @@ func queryString(tq *SQuery, tmpFields ...IQueryField) string {
208224 }*/
209225 if tq .orderBy != nil && len (tq .orderBy ) > 0 {
210226 buf .WriteString (" ORDER BY " )
211- for i , f := range tq .orderBy {
227+ for i := range tq .orderBy {
228+ f := tq .orderBy [i ]
212229 if i > 0 {
213230 buf .WriteString (", " )
214231 }
You can’t perform that action at this time.
0 commit comments