計算表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