数据如下
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方式该怎么写
结构体这样定义一下、