# SQL語法

select *

from temp_corporate.cb_cpm_2015加入;

select *

from temp_corporate.cb_cpm_2015

(select customer_ID, L1_prod_code, L1_prod_chi, sum(avg_balance), sum(total_Revenue)

from temp_corporate.cb_cpm_2015

where L1_prod_code IN ('P2','P4') AND (avg_balance > 0 or Total_revenue > 0)

GROUP BY 1,2,3,4) a

left join

(select customer_ID, L1_prod_code, L1_prod_chi, sum(avg_balance), sum(total_Revenue)

from temp_corporate.cb_cpm_2015

where L1_prod_code IN ('P1') AND (avg_balance > 0 or Total_revenue > 0)

GROUP BY 1,2,3,4) b

On a.customer_id=b.customer_id

Update:

Rating
• 逸群
Lv 5
4 years ago

select *

from temp_corporate.cb_cpm_2015

沒問題

a 跟 b 也沒問題

假設 temp_corporate.cb_cpm_2015 為C

你現在是

select *

from c

a

left join

b

我們把他用直的來看

select * from c a left join b

不覺得c跟a 中間少了甚麼嗎?

你要嘛是 select * from c left join a left join b

要嘛是 select * from c , ( a left join b )

你直接 select * from c a left join b

系統當然 會問 c 跟 a 中間 是不是要分隔

2015-07-20 18:04:03 補充：

select * from a,b 其實就等於 select * from a cross join b 交叉聯結

我們把a join b 當成D的話

select * from c,(a join b) 就會變成

select * from c cross join D

先搞清楚你要甚麼 然後在來想怎麼下語法...

2015-07-20 18:05:37 補充：

或者 你可以不要C

直接

select *

from a left join b

我想這應該是你要的

• 4 years ago

如果我要的是 select * from c , ( a left join b )

可是我在2015後加,

還是顯示error?

問題在..?

select *

from temp_corporate.cb_cpm_2015,