2017-06-22 37 views
0

我想在連接3個表後統計不同客戶的數量。這是下面的查詢。連接3個表時出錯

我得到的錯誤"mismatched input 'd' expecting) near ')' in from source"

select count(distinct(a.customer)) 
from (
    (select * 
    from tab1 
    where tab in (1)) c 
join (
    (select * 
    from tab1 
    where tab in (2)) a 
    join 
     (select * 
     from tab1 
     where tab in (3)) b 
    on a.customer = b.customer) d 
on c.customer = d.customer) 
+0

我試圖格式化您的查詢。 –

回答

0

您在查詢這是一種誤導有多餘的括號。改爲低於

select count(distinct a.customer) 
from (
    select * 
    from tab1 
    where tab in (1)) c 
join (
    select * 
    from tab1 
    where tab in (2)) a on a.customer = c.customer 
    join 
     (select * 
     from tab1 
     where tab in (3)) b on c.customer = b.customer;