1.sql对查询为null的值赋默认值
sqlserver:
select isnull(字段,0) from 表名 --这样就是把空值赋值为0
MySQL:
select ifnull(字段,0) from 表名
oracle:
select nvl(字段,0) from 表名
gorm操作
dsn := "sqlserver://sa:123456@0.0.0.0:1433?database=wzz"
gSession, err := gorm.Open(sqlserver.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
var datas []models.VALUE124200002
gSession.Table("a").
Select("a.ID,a.CODE_ID,b.AUTO_NAME as monitor_point_name, " +
"COMP1,COMP2,COMP3,COMP4,COMP5,isnull(COMP6,999),WATCH_TIME").
Where("ID BETWEEN ? AND ?", start, end).Where("b.AUTO_CODE_ID BETWEEN ? AND ?", 10000, 10012).
Joins("JOIN dbo.AUTO_CODE on a.CODE_ID = b.CODE_ID").Scan(&datas)