troubleshooting Question

SQL: Need to run query on results of query

Avatar of PresidentLincoln
PresidentLincolnFlag for United States of America asked on
DB2SQL
7 Comments1 Solution136 ViewsLast Modified:
I need to run a query on the results of another query.

First I have a query that gives me a list of customers and the products they own from my company, if those products were opened in 2019.  I need to take that list of customers and find out, of those, which ones had late fees and how much the late fees were.  Here's an example of the query I wrote that gives me the list of customers:

SELECT DISTINCT AC.CUST_NBR

FROM DB2INST1.ACCOUNT.AC

INNER JOIN DB2INST1.PRODUCTS PR ON AC.CUST_NBR = PR.CUST_NBR AND AC.ACCOUNT_NBR = PR.ACCOUNT_NBR

WHERE PR.TYPE IN (26,27) AND
AC.OPEN_DATE <= '2019-01-01' AND
(AC.CLOSE_DATE >= '2019-01-01' OR
AC.CLOSE_DATE IS NULL)

I need to now take the list of customers that query products and join in another FEES table to see which of those customers if any had fees and what the fee amount was.  What would be the easiest way to do this?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros