1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-29 17:11:29 +00:00

count func add support group by

This commit is contained in:
qAison 2016-05-27 14:34:22 +08:00
parent 8f0749ddee
commit 761b6c129c

View File

@ -927,12 +927,17 @@ func (d *dbBase) Count(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition
tables.parseRelated(qs.related, qs.relDepth) tables.parseRelated(qs.related, qs.relDepth)
where, args := tables.getCondSQL(cond, false, tz) where, args := tables.getCondSQL(cond, false, tz)
groupBy := tables.getGroupSQL(qs.groups)
tables.getOrderSQL(qs.orders) tables.getOrderSQL(qs.orders)
join := tables.getJoinSQL() join := tables.getJoinSQL()
Q := d.ins.TableQuote() Q := d.ins.TableQuote()
query := fmt.Sprintf("SELECT COUNT(*) FROM %s%s%s T0 %s%s", Q, mi.table, Q, join, where) query := fmt.Sprintf("SELECT COUNT(*) FROM %s%s%s T0 %s%s%s", Q, mi.table, Q, join, where, groupBy)
if groupBy != "" {
query = fmt.Sprintf("SELECT COUNT(*) FROM (%s) AS T", query)
}
d.ins.ReplaceMarks(&query) d.ins.ReplaceMarks(&query)