Oracle
 sql >> Datenbank >  >> RDS >> Oracle

So verbinden und extrahieren Sie in SQL

Ich glaube, Sie wollen:

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;