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
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?