gpt4 book ai didi

php - 如何加入两个大查询?

转载 作者:行者123 更新时间:2023-11-28 23:26:52 26 4
gpt4 key购买 nike

这是我的第一个查询..

SELECT cmp.bundles_id, 
MONTH(cmp.payment_date) as month,
sum(vb.bundle_price) as bundle_Price
FROM `voice_bundles` as cmp
join `voice_bundles_price` as vb
ON cmp.bundles_id=vb.id
GROUP BY MONTH(cmp.payment_date)

这是我的第二个查询..

SELECT 
MONTH(bill_due_date) as month,
sum(charges) as Intercom,
sum(package_rent) as packages_price
from `bill`
GROUP BY MONTH(bill_due_date)

我想根据月份在同一个表中显示数据...但问题是字段名称是 MONTH(bill_due_date) as monthMONTH(cmp.payment_date ) 作为月份

两个查询的月份相同..

我如何将两个查询结合起来并使其成为一个......并想要这样的输出?

enter image description here

最佳答案

你可以试试表之间的连接

select a.month, a.bundle_Price,  b.Intercom, b.packages_price
from (
SELECT cmp.bundles_id,
MONTH(cmp.payment_date) as month,
sum(vb.bundle_price) as bundle_Price
FROM `voice_bundles` as cmp
join `voice_bundles_price` as vb
ON cmp.bundles_id=vb.id
GROUP BY MONTH(cmp.payment_date) 7
) a
inner join (
SELECT
MONTH(bill_due_date) as month,
sum(charges) as Intercom,
sum(package_rent) as packages_price
from `bill`
GROUP BY MONTH(bill_due_date)
) b
on a.month = b.month

关于php - 如何加入两个大查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960875/

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