oracle - SQL Nested Calculation JOIN -
oracle - SQL Nested Calculation JOIN -
there several dozen threads title none of ones found seemed help.
i have query composed of 2 tables: table client , table transactions
each client can have multiple entries in transactions table. want given time frame (assume dates tracked within transactions table) take each client in client table , find 3 different calculations transactions table customer. first number calculates # of quotes issued, sec calculates # of orders, , 3rd total number of quotes didn't turn order. calculations don't matter relates solution problem.
i sense there type of bring together i'm not utilizing derive proper values here have far (simplified).
select customer.customerid, count(transactionalias1.*), count(transactionalias2.*), count(transactionalias3.*) client left bring together (select * transactions [...]) transactionalias1 on transactionalias1.customerid = customer.customerid left bring together (select * transactions [...]) transactionalias2 on transactionalias2.customerid = customer.customerid left bring together (select * transactions [...]) transactionalias3 on transactionalias3.customerid = customer.customerid grouping customer.customerid
what's unusual me having first 2 inner joins produces right values first 2 counts. adding 3rd inner bring together invalidates other values. running select statement within each inner bring together lone produces right count.
any help appreciated. if of aware of stackoverflow article addresses same issue, please allow me know.
shouldn't unusual - there's certainly different filter in each of 3 subqueries, unless every client has @ to the lowest degree 1 transaction each subquery, inner bring together produce result don't expect.
you should remain left bring together receive right results customers. alternatively, can this:
select customer.customerid, sum(count1) count1, sum(count2) count2, sum(count3) count3 client left bring together ( select customerid, case when ... 1 else 0 end count1, case when ... 1 else 0 end count2, case when ... 1 else 0 end count3 transactions ) s txn on txn.customerid = customer.customerid grouping customer.customerid
oracle join
Comments
Post a Comment