oracle - sql query, plsql needed? -
i have 3 tables, customer, account , orders.
a customer can have many orders, orders have customer_id foreign key.
a customer can have many accounts, account can have customer, account has customer_id foreign key.
the table account has attribute called defaulter, can true or false.
wish make following query:
- all customer orders 2 defaulter accounts.
it can done sql or plsql needed?
thank you
pl/sql not needed. query can done trivial sql dql query.
either,
join customers accounts twice, looking different accounts (for same customer) meeting "defaulter account" criteria, or
join customers accounts once , use group (on customer) having count >= 2 "defaulter account" criteria met, or
join customers accounts, group on customer , apply aggregate count when "defaulter account" criteria met count (case..). use outer query select when count >= 2, or move aggregate count clause.
if needing find "exactly two" (or number), latter 2 approaches more flexible, , having count idiomatic.
Comments
Post a Comment