Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a sum field but still see detail

Status
Not open for further replies.

sonny1974

Technical User
Feb 25, 2007
161
US
i want to see the detail but i want another field that will qty_ord and qty_rcv for each PO

so the total for PO 100001 is 6 ordered, 3 received
100002 40 order and 40 received

how would i put two more field that would give me the totals for ordered and received but also see the detail data

select
pod.po_nbr,pod.qty_ord,pod.qty_rcv,unit_prc

from pod_table pod
left join po_table po on pod.po_nbr = po.po_nbr
left join vm_table vm on pod.vendor = vm.vendor
order by pod.po_nbr, pod.po_item_nbr




PO_NBR QTY_ORD QTY_RCV UNIT_PRC
100001 2 2 1225.79
100001 1 1 1225.79
100001 2 0 1810.96
100001 1 0 1810.96
100002 10 10 0.627
100002 10 10 0.899
100002 10 10 0.396
100002 10 10 0.676
 
You need to look at windowing functions. These have the format:

select a, b, c, sum(d) over (partition by a, b)
from table
 
can i do this?

if the sum_ord = sum_rcv then a Y if the dont then N


PO_NBR QTY_ORD QTY_RCV UNIT_PRC SUM_ORD SUM_RCV
100001 2 2 1225.79 6 3
100001 1 1 1225.79 6 3
100001 2 0 1810.96 6 3
100001 1 0 1810.96 6 3
100002 10 10 0.627 40 40
100002 10 10 0.899 40 40
100002 10 10 0.396 40 40
100002 10 10 0.676 40 40
 
Sonny,

It appears that you are using SQL*Plus. In that environment, you can use this code:
Code:
break on po_nbr skip 1 on report
compute sum of qty_ord qty_rcv on po_nbr report
select * from pod_table order by po_nbr;

    PO_NBR    QTY_ORD    QTY_RCV   UNIT_PRC
---------- ---------- ---------- ----------
    100001          2          2    1225.79
                    1          1    1225.79
                    2          0    1810.96
                    1          0    1810.96
********** ---------- ----------
sum                 6          3

    100002         10         10       .627
                   10         10       .899
                   10         10       .396
                   10         10       .676
********** ---------- ----------
sum                40         40

           ---------- ----------
sum                46         43
Notice that the code sub-totals at po_nbr breaks and grand-totals at the end of the report.

Let us know if this is what you wanted.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
You can probably do that by adding a case (or decode) statement to your SQL.
 
Sonny,

If I understand your most recent question, then you can use this code (in addition to my earlier code):
Code:
col flag format a4
select pod.*
      ,decode(sign(qty_ord-qty_rcv),-1,'N',0,'Y',1,'N') flag
  from pod_table pod
 order by po_nbr;

    PO_NBR    QTY_ORD    QTY_RCV   UNIT_PRC FLAG
---------- ---------- ---------- ---------- ----
    100001          2          2    1225.79 Y
                    1          1    1225.79 Y
                    2          0    1810.96 N
                    1          0    1810.96 N
********** ---------- ----------
sum                 6          3

    100002         10         10       .627 Y
                   10         10       .899 Y
                   10         10       .396 Y
                   10         10       .676 Y
********** ---------- ----------
sum                40         40

           ---------- ----------
sum                46         43
Let us know if this resolves your question.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Geez...I'm always a minute or two behind the other posts.[blush]

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
...But at least we are not like some of the other database-vendor forums where it may be days before one sees a reply to their post. [2thumbsup]

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top