简体   繁体   English

SQL:将视图连接到表以进行查询

[英]SQL: joining view to table for query

屏幕截图错误消息

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

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是一个已经制作的视图,我想将它加入到一个表telemon_payments_data中。

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; 错误消息是说January_Cohort不是表; 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM