gpt4 book ai didi

mysql - 如何将两个查询合二为一并在单个查询中获得结果?

转载 作者:行者123 更新时间:2023-11-30 21:55:44 24 4
gpt4 key购买 nike

SELECT SUM(commission) as regularincome FROM `tbl_member_commission` where mem_id=2 AND MONTH(cdate) = MONTH(CURRENT_DATE())

SELECT SUM(commission) as crowdfund FROM `tbl_member_comm_month` where mem_id=2 AND MONTH(cdate) = MONTH(CURRENT_DATE())

注意:- 两个表都有相同的列名:佣金、mem_id、cdate

最佳答案

如果这是每个子查询中的唯一记录,您可以使用CROSS JOIN:

 select a.regularincome, b.crowdfund
FROM
(SELECT SUM(commission) as regularincome FROM `tbl_member_commission` where mem_id=2 AND MONTH(cdate) = MONTH(CURRENT_DATE())) as a
cross join
(SELECT SUM(commission) as crowdfund FROM `tbl_member_comm_month` where mem_id=2 AND MONTH(cdate) = MONTH(CURRENT_DATE())) as b

关于mysql - 如何将两个查询合二为一并在单个查询中获得结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45265161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com