From 0b1677ab9df6f325e667a6a0b93ccc6a26f50ce9 Mon Sep 17 00:00:00 2001 From: starchou Date: Wed, 14 Jan 2015 15:04:48 +0800 Subject: [PATCH] fix missing group by --- statement.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/statement.go b/statement.go index 14a8105c..18998535 100644 --- a/statement.go +++ b/statement.go @@ -1237,8 +1237,12 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) { if len(statement.OrderStr) > 0 { orderStr = " ORDER BY " + statement.OrderStr } - mssqlCondi = fmt.Sprintf("(%s NOT IN (SELECT TOP %d %s%s%s%s))", - column, statement.Start, column, fromStr, whereStr, orderStr) + var groupStr string + if len(statement.GroupByStr) > 0 { + groupStr = " GROUP BY " + statement.GroupByStr + } + mssqlCondi = fmt.Sprintf("(%s NOT IN (SELECT TOP %d %s%s%s%s%s))", + column, statement.Start, column, fromStr, whereStr, orderStr, groupStr) } }