If it was me I would have a date field on the salesman/salesperson table that show the
date that their sales went over $1,000,000. I would then have an update statement that
would look for salesman/salesperson that have "milliondollarsalesdate" of null and sales
over one million. You can update the "milliondollarsalesdate" to TRUNC(SYSDATE)
Something like:
You may want to create a PL/SQL collection of rows to update and update it with a forall,Code:UPDATE salesperson SET milliondollarsalesdate=TRUNC(SYSDATE) WHERE milliondollarsalesdate IS NULL AND sales_person_id IN ( SELECT SALES_PERSON_ID FROM SALES WHERE SALE_DATE > TRUNC(SYSDATE, 'MM') GROUP BY SALES_PERSON_ID, customer_id HAVING SUM(sale_value) > 1000000 );
that way you can do an inner join rather than a wehre in. The difference is the difference
between a non-correlated and correlated subquery. And yes you can put this into a PL/SQL
stored procedure, you need to get the logic first, then figure out how to write it.




Reply With Quote