calculation field(summary) [message #293493] |
Sun, 13 January 2008 07:41 |
ashraf_al_ani
Messages: 92 Registered: October 2007 Location: Iraq
|
Member |
|
|
Dear all
I have 2 datablock in one canvas and the relation between them is one to many I want a field in the master table called"total"
calculate for me a field in the foreign table called "sub_total"
so how can I use the "summary" for this calculation
best wishes
the master datablock name is "invoice"
the foreign datablock is called "details_invoice"
best wishes
|
|
|
|
|
|
|
Re: calculation field(summary) [message #293632 is a reply to message #293551] |
Mon, 14 January 2008 05:45 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
If I understood you correctly, this is what you currently have:CREATE TABLE master
(id NUMBER PRIMARY KEY,
name VARCHAR2(20),
total NUMBER
);
CREATE TABLE detail
(id_fk NUMBER CONSTRAINT fk_dm
REFERENCES master (id),
sub_total NUMBER
); A sample data might be this:
detail: id_fk sub_total
----- ---------
1 10
1 20
2 50
master: id total
-- -----
1 30 (= 10 + 20)
2 50
If that's really what you have, perhaps you should consider whether it is a good idea to keep the summary of all sub_totals per ID in the master table. Why would you do that? A simple query will return that value any time:SELECT m.id, m.name, SUM(d.sub_total) total
FROM MASTER m, DETAIL d
WHERE m.id = d.id_fk
GROUP BY m.id, m.name; In my opinion, there's really NO NEED to keep totals in the master table.
However, if I misunderstood the question, here's a sample form (created with Forms 10g) based on Scott's schema. It will only show you how to create a summary item for display purposes. Modify it in order to suit your real needs. Perhaps it'll help.
|
|
|
|