Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Como juntar e extrair no SQL


Acho que você quer:
select customer,
       sum(case when area = 'X' then 1 else 0 end) as x,
       sum(case when area = 'Y' then 1 else 0 end) as y
from t1
where exists (select 1
              from t1 tt1
              where tt1.customer = t1.customer and tt1.product = 'A'
             )
group by customer;