func AppOperateRecharge(a *decorator.ApiBase) error { logger.AccessLogger.Info("AppOperateRecharge...") resp := adminStruct.BusinessOrderRechargeResponse{} resp.ResponseCommon = a.NewSuccessResponseCommon() a.Ts.Table("business_base as a"). Select("s.bid, a.bname, s.acct_bal,s.buy_sum_amt, " + "sum(CASE WHEN b.stmt_status = 1 THEN a.stmt_amt ELSE 0 END) as unpaid_amt, " + "sum(CASE WHEN b.stmt_status = 0 THEN a.stmt_amt ELSE 0 END) as stmt_amt, " + "a.admin_uid, u.user_name, a.status"). Joins("left join business_bal as s on s.bid=a.bid"). Joins("left join user_base as u on u.uid=a.admin_uid"). Joins("left join business_settlement as b on b.bid=a.bid"). Group("a.bid").Offset(a.Offset). Limit(a.Size).Count(&resp.Count). Find(&resp.Data) return a.ReturnSuccessCustomResponse(resp) } 转为mysql语言查询
时间: 2024-04-21 22:22:28 浏览: 122
Python 基础课程《16.函数使用进阶》
这段代码使用Golang的GORM库来构建一个MySQL查询语句。下面是将该代码转换为MySQL语言查询的版本:
```sql
SELECT
s.bid, a.bname, s.acct_bal, s.buy_sum_amt,
SUM(CASE WHEN b.stmt_status = 1 THEN a.stmt_amt ELSE 0 END) AS unpaid_amt,
SUM(CASE WHEN b.stmt_status = 0 THEN a.stmt_amt ELSE 0 END) AS stmt_amt,
a.admin_uid, u.user_name, a.status
FROM
business_base AS a
LEFT JOIN
business_bal AS s ON s.bid = a.bid
LEFT JOIN
user_base AS u ON u.uid = a.admin_uid
LEFT JOIN
business_settlement AS b ON b.bid = a.bid
WHERE
a.bid = ?
GROUP BY a.bid
OFFSET ?
LIMIT ?
```
请注意,这是一个近似的转换,可能需要根据你的具体数据库结构和需求进行调整。在查询中,`?` 是占位符,表示查询参数的值,你需要将其替换为实际的值。另外,`OFFSET` 和 `LIMIT` 是用于分页的参数,你需要根据具体情况设置它们的值。
希望这能帮到你!如果有任何进一步的问题,请随时提问。
阅读全文