所以我有这个查询,它计算了一些汽车,并且应该将数字保存为int变量,但不起作用:
db := dbGorm.GetDB()
var cars int64
db.Raw(`SELECT COUNT(park_id) AS parkedCars FROM prk_park WHERE to_date = NULL`).Scan(&cars)
return cars
好吧,显然我所需要做的就是在.Scan()之前添加.Row。>
db := dbGorm.GetDB()
var cars int
_ = db.Raw(`SELECT COUNT(park_id) AS parkedCars FROM prk_park WHERE to_date IS NULL`).
Row().Scan(&cars)
return cars