浏览代码

获取总数

xyxie 3 月之前
父节点
当前提交
46e958d9e6
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      models/chart_collect/chart.go

+ 3 - 2
models/chart_collect/chart.go

@@ -123,14 +123,15 @@ func GetChartCollectDetailByCondition(condition string, pars []interface{}) (ite
 
 func GetChartCollectCountByCondition(condition string, pars []interface{}) (total int64, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT 	count(*) AS num FROM chart_collect AS a INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id
+	sql := `SELECT 	a.chart_info_id FROM chart_collect AS a INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id
 			WHERE 1=1 
 			`
 	if condition != "" {
 		sql += condition
 	}
 	sql += ` GROUP BY a.chart_info_id`
-	err = o.Raw(sql, pars).QueryRow(&total)
+	totalSql := `select count(1) as total from (` + sql + `) as t`
+	err = o.Raw(totalSql, pars).QueryRow(&total)
 	return
 }