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,

  1. join customers accounts twice, looking different accounts (for same customer) meeting "defaulter account" criteria, or

  2. join customers accounts once , use group (on customer) having count >= 2 "defaulter account" criteria met, or

  3. 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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -