Snippet Name: EXISTS 2
Description: Another example of the use of the 'EXISTS' clause.
Also see: » AND Condition
» Distinct
» Having Clause
» EXISTS
» WITH with CONNECT BY
» WITH Clause: Single alias
» WITH Clause: Double alias
Comment: (none)
Language:
Highlight Mode: PLSQL
Last Modified: March 01st, 2009
|
SELECT DISTINCT(aps.customer_id),
rc.customer_number,
rc.customer_name,
SUM(aps.amount_due_remaining)
FROM ar_payment_schedules aps, ra_customers rc
WHERE aps.customer_id = rc.customer_id
AND aps.class IN ('CM', 'PMT', 'INV')
AND aps.status = 'OP'
AND EXISTS (
SELECT a.customer_id
FROM ar_payment_schedules a
WHERE a.customer_id = aps.customer_id
AND aps.status = 'OP'
AND aps.class IN ('CM', 'PMT', 'INV')
AND TO_CHAR(aps.trx_date, 'J') <= '30-SEP-95'
GROUP BY aps.customer_id)
GROUP BY aps.customer_id, rc.customer_number, rc.customer_name; |