使用到
实现sql:
SELECT count(1) FROM (SELECT 1 FROM tb_map_total WHERE deleted = 0 AND seasonId IN (1000016) AND stageIdList IN ('10008','10007') GROUP BY useMapId) AS tmp
Go
subBuilder := squirrel.Select("1").From(m.table).Where(squirrel.Eq{"deleted": 0})
if len(seasonIdList) > 0 {
subBuilder = subBuilder.Where(squirrel.Eq{"seasonId": seasonIdList})
}
if len(stageIdList) > 0 {
subBuilder = subBuilder.Where(squirrel.Eq{"stageIdList": stageIdList})
}
subBuilder = subBuilder.GroupBy("useMapId")
builder := squirrel.Select("count(1)").FromSelect(subBuilder, "tmp")
sql, args, err := builder.ToSql()
if err != nil {
return 0
}
var resp int64
err = m.conn.QueryRowCtx(ctx, &resp, sql, args...)
switch err {
case nil:
return resp
default:
return 0
}