Trying to get highest 20 rows of the below query based on “Net Amount in USD” column which is a sum column. Any clues?
select
INVOICE.IDENTITY as "Identity", supplier.vendor_name, to_char(sum(INVOICE.ACTUAL_NET_DOM_AMOUNT), '$999,999,999') as "Net Amount in USD"
from &AO.INVOICE
inner join
&AO.supplier
on &AO.Invoice.identity = &AO.supplier.vendor_no
where INVOICE.OBJSTATE <> 'Cancelled'
group by
INVOICE.IDENTITY,vendor_name
Best answer by Tomas Ruderfelt
Like this, had to remove &AO when I tested but I guess you get the idea:
SELECT i.identity "Supplier ID", s.vendor_name "Supplier Name", to_char(sum(i.actual_net_dom_amount), '$999,999,999') as "Net Amount in USD" FROM invoice i INNER JOIN supplier s ON i.identity = s.vendor_no WHERE i.objstate <> 'Cancelled' AND i.party_type_db = 'SUPPLIER' GROUP BY i.identity,s.vendor_name ORDER BY sum(i.actual_net_dom_amount) DESC FETCH FIRST 20 ROWS ONLY
Like this, had to remove &AO when I tested but I guess you get the idea:
SELECT i.identity "Supplier ID", s.vendor_name "Supplier Name", to_char(sum(i.actual_net_dom_amount), '$999,999,999') as "Net Amount in USD" FROM invoice i INNER JOIN supplier s ON i.identity = s.vendor_no WHERE i.objstate <> 'Cancelled' AND i.party_type_db = 'SUPPLIER' GROUP BY i.identity,s.vendor_name ORDER BY sum(i.actual_net_dom_amount) DESC FETCH FIRST 20 ROWS ONLY
Like this, had to remove &AO when I tested but I guess you get the idea:
SELECT i.identity "Supplier ID", s.vendor_name "Supplier Name", to_char(sum(i.actual_net_dom_amount), '$999,999,999') as "Net Amount in USD" FROM invoice i INNER JOIN supplier s ON i.identity = s.vendor_no WHERE i.objstate <> 'Cancelled' AND i.party_type_db = 'SUPPLIER' GROUP BY i.identity,s.vendor_name ORDER BY sum(i.actual_net_dom_amount) DESC FETCH FIRST 20 ROWS ONLY