SQL語法

請問各位高手

我打入這樣的語法,但產生3707: syntax error, expected something like ';' between the word 'cb_cpm_2015' and '('

若於

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:

可是..

我若直接 select * from c , ( a left join b )

語法是如下嗎?可否解疑? 謝謝

2 Answers

Rating
  • 逸群
    Lv 5
    4 years ago
    Favorite Answer

    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,

Still have questions? Get your answers by asking now.