golang分组

yi0zb3m4  于 2021-06-19  发布在  Mysql
关注(0)|答案(0)|浏览(289)

我有一个mysql查询,结构和代码如下:

sqlQuery := "SELECT group_concat(Id), Title from Tbl WHERE SomeField = 3 GROUP BY Title ORDER BY Title LIMIT 20;"
type SomeStruct struct {
    IDs            []int    `json:"ids"`
    Title          string   `json:"title"`
    SomeField      int      `json:"somefield"`
}

type SomeMap map[string]interface{}

var SomeObject []SomeMap

row, err := db.Query(sqlQuery)
checkErr(err)
for row.Next() {
   var ids []int
   var title string
   var somefield int

   err = row.Scan(&ids, &title, &somefield)
   someMap := SomeMap{"ids":ids, "title": title, "somefield": somefield}
   someObject = append(SomeObject, someMap)
}

我如何将我的对象解构到结构中,其中id看起来像[]int type,因为golang告诉它可能是[]uint8??

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题