gpt4 book ai didi

mysql - SQL:将 View 连接到表以进行查询

转载 作者:行者123 更新时间:2023-11-30 22:02:12 25 4
gpt4 key购买 nike

screenshot error message here

SELECT January.customer_id as Jancust_id,
SUM(payments.payment) as Jan_cust_pmts,
COUNT(DISTINCT January.customer_id) AS Jan_orig_cust,
COUNT(DISTINCT payments.customer_id) as Jan_ret_cust,
AVG(payments.payment) as Cust_life_rev
January.acquisition_source as Jan_source
FROM January_Cohort January
LEFT JOIN telemon_payments_data payments
ON January.customer_id = payments.customer_id
GROUP BY Jan_source

所以上面应该是一个查询,其中 January_Cohort 是一个已经创建的 View ,我想将它加入表 telemon_payments_data。

我是指错了,还是我不能连接表和 View ?
错误消息说 January_Cohort 不是表格;我知道,这是一种观点。

最佳答案

也许它会起作用将 View 作为子查询表

SELECT January.customer_id as Jancust_id,
SUM(payments.payment) as Jan_cust_pmts,
COUNT(DISTINCT January.customer_id) AS Jan_orig_cust,
COUNT(DISTINCT payments.customer_id) as Jan_ret_cust,
AVG(payments.payment) as Cust_life_rev
January.acquisition_source as Jan_source
FROM (select * from January_Cohort) January
LEFT JOIN telemon_payments_data payments
ON January.customer_id = payments.customer_id
GROUP BY Jan_source

关于mysql - SQL:将 View 连接到表以进行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43038500/

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