How to display SUM fields from a detailed table in a master table

Posted by max on Stack Overflow See other posts from Stack Overflow or by max
Published on 2010-05-10T12:17:29Z Indexed on 2010/05/10 12:34 UTC
Read the original article Hit count: 274

Filed under:
|
|

What is the best approach to display the summery of DETAILED.Fields in its master table?

E.g. I have a master table called 'BILL' with all the bill related data and a detailed table ('BILL_DETAIL') with the bill detailed related data, like NAME, PRICE, TAX, ... Now I want to list all BILLS, without the details, but with the sum of the PRICE and TAX stored in the detail table.

Here is a simplified schema of that tables:

TABLE BILL
----------
- ID
- NAME
- ADDRESS
- ...

TABLE BILL_DETAIL
-----------------
- ID
- BILLID
- PORDUCT_NAME
- PRICE
- TAX
- ...

The retrieved table row should look like this:

BILL.CUSTOMER_NAME, BILL.CUSTOMER_ADDRESS, sum(BILL_DETAIL.PRICE), sum(BILL.DETAIL.TAX), ...

Any sugguestions?

© Stack Overflow or respective owner

Related posts about sql

Related posts about database