mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 02:51:28 +00:00
count func add support group by
This commit is contained in:
parent
8f0749ddee
commit
761b6c129c
@ -927,12 +927,17 @@ func (d *dbBase) Count(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition
|
||||
tables.parseRelated(qs.related, qs.relDepth)
|
||||
|
||||
where, args := tables.getCondSQL(cond, false, tz)
|
||||
groupBy := tables.getGroupSQL(qs.groups)
|
||||
tables.getOrderSQL(qs.orders)
|
||||
join := tables.getJoinSQL()
|
||||
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user