2017-06-22 51 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;