- 62
- 0
数据如下
| issue_type | taskstatus |
|---|---|
| TEST | 1 |
| RDC | 0 |
| RDC | 0 |
| RDC | 0 |
| RDC | 0 |
| RDC | 0 |
| RDC | 0 |
| OPS | 0 |
| RDC | 0 |
| RDC | 0 |
select a.issue_type as issue_type , a.totalcount as totalcount , b.donecount as donecount from (select issue_type, count(issue_type) as totalcount from coot_work_order group by issue_type) as a, (select issue_type, count(taskstatus) as donecount from coot_work_order where taskstatus = 0 group by issue_type) as b where a.issue_type = b.issue_type;
通过sql执行结果为
[{OPS 1 0} {RDC 8 0} {TEST 1 1}]
定义struct
type TotalIssue struct {
IssueType string `json:"issue_type"`
Totalcount int `json:"totalcount"`
Donecount int `json:"donecount"`
}
var result []TotalIssue
sql := "select a.issue_type as issue_type , a.totalcount as totalcount , b.donecount as donecount from (select issue_type, count(issue_type) as totalcount from coot_work_order group by issue_type) as a, (select issue_type, count(taskstatus) as donecount from coot_work_order where taskstatus = 0 group by issue_type) as b where a.issue_type = b.issue_type;"
db.Table("coot_work_order").Raw(sql).Scan(&result).Debug()
通过go执行结果为
[{OPS 0 0} {RDC 0 0} {TEST 0 0}]
为啥呀,另外求教不写sql方式该怎么写
0
打赏
收藏
点击回答
您的回答被采纳后将获得:提问者悬赏的 10 元积分
- 共 0 条
- 全部回答
-
老烟枪 普通会员 1楼
在使用Go的ORM框架(如GORM)时,查询数据库的问题可能会出现在多个方面。以下是一些常见的问题和解决方案:
orm select或orm selectList:当在ORM查询中使用select或selectList方法时,你需要确保你的数据库已经正确地设置了相应的列。例如,如果你的表有id,name和email三个列,你需要使用select或selectList方法选择id和email这两个列。
go db.Where("id = ?", id).Select("name, email")orm insert或orm insertList:当你在ORM查询中使用insert或insertList方法时,你需要确保你的数据库已经正确地设置了相应的表和列。例如,如果你的表有id,name和email三个列,你需要使用insert或insertList方法插入id,name和email这三个列。
go db.Insert(&User{ID: id, Name: name, Email: email})orm delete或orm deleteList:当你在ORM查询中使用delete或deleteList方法时,你需要确保你的数据库已经正确地设置了相应的表和列。例如,如果你的表有id,name和email三个列,你需要使用delete或deleteList方法删除id,name和email这三个列。
go db.Delete(&User{ID: id})orm update或orm updateList:当你在ORM查询中使用update或updateList方法时,你需要确保你的数据库已经正确地设置了相应的表和列。例如,如果你的表有id,name和email三个列,你需要使用update或updateList方法更新id,name和email这三个列。
go db.Update(&User{ID: id, Name: name, Email: email})orm bind或orm bindList:当你在ORM查询中使用bind或bindList方法时,你需要确保你的参数已经被正确地绑定到你的字段。例如,如果你有一个名为user的字段,你可以使用bind或bindList方法来绑定一个User对象。
go db.Bound(&User{ID: id, Name: name, Email: email})以上是一些基本的查询问题和解决方案。具体的查询语法可能会根据你的数据库和ORM框架有所不同。
更多回答
网站公告
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
