mysql连表统计查询问题,求助
问题描述
问题解答
回答1:select u2.username as borrower,u1.username as debtor,sum(b.amount) as debt from borrow_log b left join users u1 on b.debtor = u1.id left join users u2 on b.borrower = u2.id where u1.gender = 1 group by b.borrower,b.debtor;回答2:
SELECT (SELECT us.username FROM users us WHERE us.id=a.borrow) AS borrow_name, (SELECT us.username FROM users us WHERE us.id=a.debtor) AS debtor_name, SUM(amount) AS total_amount FROM borrow_log a LEFT JOIN users b ON a.debtor = b.id WHERE b.gender = 1 GROUP BY a.borrow,a.debtor回答3:
SELECT a1.*,a2.username AS debname,a3.username AS borrowname,SUM(a1.amount) FROM a1 LEFT JOIN a2 ON a1.debtor=a2.id LEFT JOIN a2 AS a3 ON a1.borrower=a3.id WHERE a2.gender=1 GROUP BY a1.debtor ,a1.borrower
相关文章:
1. JAVASCRIPT 构造函数和原型互相指向问题?求助!!!2. 求助:JAVA加密的数据PHP解密3. angular.js - angular post的Content-Type被设置,导致不能上传图片,求助!!4. php安装lpsolve 扩展求助5. javascript - 关于addEventListener和attachEvent的兼容写法疑问,求助!6. javascript - vue生成一维码?求助!!!!!急7. 非root安装MySQL5.6报错,求助!!!8. ueditor上传服务器提示后端配置项没有正常加载,求助!!!!!9. 求助python安装mysql模块出错10. 调用百度翻译API,在JAVA项目可以翻译,在android中却不行。求助

网公网安备