SlideShare a Scribd company logo
1 of 3
Example of complicatedSQLusing join,innerjoin,andself join topresentareportoninvoices$
amountsspentagainsttheirPurchase Order. The resultisdisplayedonPage 3.
selectpo_id,
vendor,
po_number,
po_short_description,
po_type,
po_amount,
inv_total_pending,
inv_total_paid,
inv_total_rejected,
inv_total,
cast(round(nvl(inv_total/po_amount,0),2)*100as varchar(10))||'%'percent
from
(selectb.po_id,
b.vendor,
b.po_number,
b.po_short_description,
b.po_type,
b.po_amount,
h.inv_total_pending,
h.inv_total_paid,
h.inv_total_rejected,
h.inv_total
from
(selectpo.po_id,vendor,po_number,po_short_description,po_type,sum(po_det_amt) po_amount
frompo,po_details
where po.po_id=po_details.po_id
and po_details.po_status<>'CLOSED'
and po_details.work_order_numberin(selectwo_xref.wo_number_idfromwo_xref,project
where wo_xref.wo_number_id=project.work_order_number
and project.project_number=nvl(substr(:F101_FPC_NUMBER,1,10),project.project_number))
groupby po.po_id,vendor,po_number,po_short_description,po_type)b,
(selectf.vendor,
f.po_number,
f.inv_total_paid,
f.inv_total,
f.inv_total_pending,
g.inv_total_rejected
from
(selectd.vendor,
d.po_number,
d.inv_total_paid,
d.inv_total,
inv_total_pending
from
(selecta.vendor,
a.po_number,
inv_total_paid,
inv_total
from
(selectvendor,po_number,sum(nvl(inv_det_amount,0))inv_total
frominvoice,invoice_details,project
where invoice.inv_id=invoice_details.inv_id
and invoice_details.work_order_number=project.work_order_number
and project.project_number=nvl(:F101_FPC_NUMBER,project.project_number)
groupby vendor,po_number)a,
(selectinvoice.vendor,
invoice.po_number,
sum(nvl(inv_det_amount,0))inv_total_paid
frominvoice,invoice_details,project
where invoice.inv_id=invoice_details.inv_id
and invoice_details.work_order_number=project.work_order_number
and project.project_number=
nvl(substr(:F101_FPC_NUMBER,1,10),project.project_number)
and invoice.inv_status='PAID'
groupby vendor,po_number)c
where a.po_number=c.po_number(+))d,
(selectinvoice.vendor,
invoice.po_number,
sum(nvl(inv_det_amount,0))inv_total_pending
frominvoice,invoice_details,project
where invoice.inv_id=invoice_details.inv_id
and invoice_details.work_order_number=project.work_order_number
and project.project_number=
nvl(substr(:F101_FPC_NUMBER,1,10),project.project_number)
and invoice.inv_status='PENDING'
groupby vendor,po_number)e
where d.po_number=e.po_number(+))f,
(selectinvoice.vendor,
invoice.po_number,
sum(nvl(inv_det_amount,0))inv_total_rejected
frominvoice,invoice_details,project
where invoice.inv_id=invoice_details.inv_id
and invoice_details.work_order_number=project.work_order_number
and project.project_number=
nvl(substr(:F101_FPC_NUMBER,1,10),project.project_number)
and invoice.inv_status='REJECTED'
groupby vendor,po_number)g
where f.po_number=g.po_number(+))h
where b.po_number=h.po_number(+))
where po_amount<> 0
orderby round(nvl(inv_total/po_amount,0),2)*100DESC
And the resultlooks like:

More Related Content

Viewers also liked (15)

Resume MG
Resume MGResume MG
Resume MG
 
43-Report Spring
43-Report Spring43-Report Spring
43-Report Spring
 
The question
The questionThe question
The question
 
Moving beyond email
Moving beyond emailMoving beyond email
Moving beyond email
 
Aircraft Performance and Design Project Code
Aircraft Performance and Design Project CodeAircraft Performance and Design Project Code
Aircraft Performance and Design Project Code
 
Autonomous Vehicles Project
Autonomous Vehicles ProjectAutonomous Vehicles Project
Autonomous Vehicles Project
 
Физиогномика
ФизиогномикаФизиогномика
Физиогномика
 
Latest Trends in Oil/Gas Claims
Latest Trends in Oil/Gas ClaimsLatest Trends in Oil/Gas Claims
Latest Trends in Oil/Gas Claims
 
Latest Trends in Oil/Gas Claims
Latest Trends in Oil/Gas ClaimsLatest Trends in Oil/Gas Claims
Latest Trends in Oil/Gas Claims
 
presentation
presentationpresentation
presentation
 
Christ_Santos_LiquidatedDamagesThePenaltyForFailingToAchieveTheImpossible_201...
Christ_Santos_LiquidatedDamagesThePenaltyForFailingToAchieveTheImpossible_201...Christ_Santos_LiquidatedDamagesThePenaltyForFailingToAchieveTheImpossible_201...
Christ_Santos_LiquidatedDamagesThePenaltyForFailingToAchieveTheImpossible_201...
 
Ganesan Plant Inspector_CV
Ganesan Plant Inspector_CVGanesan Plant Inspector_CV
Ganesan Plant Inspector_CV
 
Fog computing paper presentation
Fog computing paper presentationFog computing paper presentation
Fog computing paper presentation
 
Reclaiming control of your business communication
Reclaiming control of your business communicationReclaiming control of your business communication
Reclaiming control of your business communication
 
Silabo del taller de danza
Silabo del taller de danzaSilabo del taller de danza
Silabo del taller de danza
 

RFS PO % Spent

  • 1. Example of complicatedSQLusing join,innerjoin,andself join topresentareportoninvoices$ amountsspentagainsttheirPurchase Order. The resultisdisplayedonPage 3. selectpo_id, vendor, po_number, po_short_description, po_type, po_amount, inv_total_pending, inv_total_paid, inv_total_rejected, inv_total, cast(round(nvl(inv_total/po_amount,0),2)*100as varchar(10))||'%'percent from (selectb.po_id, b.vendor, b.po_number, b.po_short_description, b.po_type, b.po_amount, h.inv_total_pending, h.inv_total_paid, h.inv_total_rejected, h.inv_total from (selectpo.po_id,vendor,po_number,po_short_description,po_type,sum(po_det_amt) po_amount frompo,po_details where po.po_id=po_details.po_id and po_details.po_status<>'CLOSED' and po_details.work_order_numberin(selectwo_xref.wo_number_idfromwo_xref,project where wo_xref.wo_number_id=project.work_order_number and project.project_number=nvl(substr(:F101_FPC_NUMBER,1,10),project.project_number)) groupby po.po_id,vendor,po_number,po_short_description,po_type)b, (selectf.vendor, f.po_number, f.inv_total_paid, f.inv_total, f.inv_total_pending, g.inv_total_rejected from (selectd.vendor, d.po_number, d.inv_total_paid, d.inv_total, inv_total_pending from (selecta.vendor,
  • 2. a.po_number, inv_total_paid, inv_total from (selectvendor,po_number,sum(nvl(inv_det_amount,0))inv_total frominvoice,invoice_details,project where invoice.inv_id=invoice_details.inv_id and invoice_details.work_order_number=project.work_order_number and project.project_number=nvl(:F101_FPC_NUMBER,project.project_number) groupby vendor,po_number)a, (selectinvoice.vendor, invoice.po_number, sum(nvl(inv_det_amount,0))inv_total_paid frominvoice,invoice_details,project where invoice.inv_id=invoice_details.inv_id and invoice_details.work_order_number=project.work_order_number and project.project_number= nvl(substr(:F101_FPC_NUMBER,1,10),project.project_number) and invoice.inv_status='PAID' groupby vendor,po_number)c where a.po_number=c.po_number(+))d, (selectinvoice.vendor, invoice.po_number, sum(nvl(inv_det_amount,0))inv_total_pending frominvoice,invoice_details,project where invoice.inv_id=invoice_details.inv_id and invoice_details.work_order_number=project.work_order_number and project.project_number= nvl(substr(:F101_FPC_NUMBER,1,10),project.project_number) and invoice.inv_status='PENDING' groupby vendor,po_number)e where d.po_number=e.po_number(+))f, (selectinvoice.vendor, invoice.po_number, sum(nvl(inv_det_amount,0))inv_total_rejected frominvoice,invoice_details,project where invoice.inv_id=invoice_details.inv_id and invoice_details.work_order_number=project.work_order_number and project.project_number= nvl(substr(:F101_FPC_NUMBER,1,10),project.project_number) and invoice.inv_status='REJECTED' groupby vendor,po_number)g where f.po_number=g.po_number(+))h where b.po_number=h.po_number(+)) where po_amount<> 0 orderby round(nvl(inv_total/po_amount,0),2)*100DESC