计算表lb_ytt_user_money_log 中,字段money的和
代码如下:
var total_money []int
sqlstr := `select
SUM(money) as total_money
from
lb_ytt_user_money_log
where
user_id = ? and l_type = 1 and status=1 and (create_time> ? and create_time <= ?)`
Db.Raw(sqlstr, userID, beginTimeNum, endTimeNum).Pluck("SUM(money) as total_money", &total_money)
关键在于:Pluck
Db.Raw(sqlstr, userID, beginTimeNum, endTimeNum).Pluck("SUM(money) as total_money", &total_money)
如果把Db.Pluck换成Db.scan得出的就是0