SQL:将视图联接到表以进行查询 [英] SQL: joining view to table for query
本文介绍了SQL:将视图联接到表以进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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是已经创建的视图,我想将其加入到表telemon_payments_data中.
So the above is supposed to be a query where January_Cohort is a view that was already made, and I'm wanted to join it to a table telemon_payments_data.
我是说错了吗,还是不能联接表和视图?
错误消息说January_Cohort不是一个表;我知道,这是一个视图.
Am I referring to it wrong, or can I not join a table and a view?
The error message is saying January_Cohort is not a table; which I know, it's a view.
推荐答案
可能会起作用 将视图作为子查询表
may be it will work make view as sub-query table
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
这篇关于SQL:将视图联接到表以进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文