Select(`s.bid, a.bname, s.acct_bal, s.buy_sum_amt, ifnull(sum(CASE WHEN b.stmt_status = 1 THEN b.stmt_amt ELSE 0 END), 0) as unpaid_amt, ifnull(sum(CASE WHEN i.epay_status=0 and i.contract_no='' THEN i.order_amt ELSE 0 END and i.link_id=a.bid),0)as pur_no_sett, ifnull(sum(CASE WHEN b.stmt_status = 0 THEN b.stmt_amt ELSE 0 END), 0 )as stmt_amt, a.admin_uid, u.user_name, a.status`). Joins("left join source_pay_info as i on i.link_id=a.bid"). 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").转为mysql查询语言
时间: 2024-04-21 13:22:42 浏览: 120
将代码转换为 MySQL 查询语句如下所示:
```sql
SELECT
s.bid,
a.bname,
s.acct_bal,
s.buy_sum_amt,
IFNULL(SUM(CASE WHEN b.stmt_status = 1 THEN b.stmt_amt ELSE 0 END), 0) AS unpaid_amt,
IFNULL(SUM(CASE WHEN i.epay_status = 0 AND i.contract_no = '' AND i.link_id = a.bid THEN i.order_amt ELSE 0 END), 0) AS pur_no_sett,
IFNULL(SUM(CASE WHEN b.stmt_status = 0 THEN b.stmt_amt ELSE 0 END), 0) AS stmt_amt,
a.admin_uid,
u.user_name,
a.status
FROM
business_base AS a
LEFT JOIN
source_pay_info AS i ON i.link_id = a.bid
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
GROUP BY
a.bid
```
上述代码将 `Select` 函数中的选择字段和聚合逻辑转换为 MySQL 查询语句。`Joins` 函数中的表连接部分也被转换为相应的 LEFT JOIN 语句。最后,通过 `GROUP BY` 子句对结果进行分组。
请注意,这只是代码的转换,如果还有其他地方需要修改,请在转换后的查询语句上进行相应的调整。
阅读全文