type MaxIdStruct struct MaxId int64 jsonmaxId获取db最大的id取出来老是0请问下面sql有什么问题type MaxIdStruct struct MaxId int64 jsonmaxId maxIdVal = MaxIdStruct result = dbRawselect maxid as maxId from wemeet_agency_cu
可能是因为数据库表中没有任何记录,导致查询出来的结果是空,进而导致maxIdVal的值仍然是0。建议先确认数据库表中是否有记录,或者尝试使用COALESCE函数将结果设置为非空值。例如:
maxIdVal := MaxIdStruct{} result := db.Raw("select COALESCE(max(id), 0) as maxId from wemeet_agency_customer").Scan(&maxIdVal)
原文地址: https://www.cveoy.top/t/topic/hfQt 著作权归作者所有。请勿转载和采集!