Finding the MIN value from the SUM of multiple row grouped by some id - sql

I am using SQLplus connecting to oracle database 12c
I have two tables, Customer and Account, where customers can have multiple accounts (one customer id, but multiple account types). I am trying to get the information on the customer with the largest amount of debt. Suppose we have the following information:
Customer table:
BSB# Customer# Name Address
------------------------------
0123 123456 Adam ABC st
0234 234566 Dave CBC rd
0345 345667 Max DSE st
Account table:
BSB# Customer# Type Balance
---------------------------------
0123 123456 Saving -2300
0123 123456 Credit -500
0123 123456 iSaver 200
0234 234566 Saving 5000
0345 345667 Credit -1500
0345 345667 iSaver -200
The desired output:
Customer# Name Address
-------------------------
123456 Adam ABC St
I can print out the sum of everyone's account balance, but I am not sure how to print out just the information on the account with the lowest accumulated balance. I tried using MIN(SUM(A.Balance)) but I keep getting the error saying "not a single-group function". I wouldn't be surprised if I made a mistake somewhere.
I am relatively new to sql and this is what I have so far. Any advice or pointers would be nice...
SELECT C.Customer#, C.Name, Address, SUM(A.Balance)
FROM Customer C
RIGHT OUTER JOIN Account A
ON C.BSB# = A.BSB#
AND
C.Customer# = A.Customer#
GROUP BY C.Customer#, C.Name, Address;
Thanks!

The following will order the customers by the sum of the balances:
SELECT C.Customer#, C.Name, Address, SUM(A.Balance)
FROM Customer C JOIN
Account A
ON C.BSB# = A.BSB# AND
C.Customer# = A.Customer#
GROUP BY C.Customer#, C.Name, Address
ORDER BY SUM(A.Balance);
If you want only one row, then that depends on the database. Here are some methods:
Change the select to:
SELECT TOP 1 . . .
Add a limit clause to the end of the query:
LIMIT 1
Add a fetch clause to the end of the query:
FETCH FIRST 1 ROWS ONLY
And in Oracle, you can do this with a subquery:
SELECT *
FROM (SELECT C.Customer#, C.Name, Address, SUM(A.Balance)
FROM Customer C JOIN
Account A
ON C.BSB# = A.BSB# AND
C.Customer# = A.Customer#
GROUP BY C.Customer#, C.Name, Address
ORDER BY SUM(A.Balance)
) t
WHERE rownum = 1;

U can use the folowing statement
with MinAccounts as
(
SELECT BSB#, Customer#, Balance
FROM (
SELECT BSB#, t.Customer# , sum(t.Balance) Balance, min(sum(t.Balance)) over () minBalance
FROM Account t
GROUP BY BSB#, Customer#
) d
WHERE Balance = minBalance)
SELECT *
FROM MinAccounts a
JOIN Customer c ON a.BSB# = c.BSB#

Related

Ignore duplicate data id in SQL Query?

How do I ignore duplicate data ids from query SQL results:
In this case I tried to combine several tables. Like this scheme that I made:
Transactions
----------------------------------------------------------------------------------------
id
user_id
type
amount
invoice_transaction (Relation to invoice)
created_at
updated_at
Users
----------------------------------------------------------------------------------------
id
name
email
phone
birth
address
picture
created_at
updated_at
Vouchers
----------------------------------------------------------------------------------------
id
code
amount
type
created_at
updated_at
Vouchers Transactions
----------------------------------------------------------------------------------------
id
user_id
voucher_id
created_at
updated_at
invoice
----------------------------------------------------------------------------------------
id
order_data
payment_id
last_total
status
created_at
updated_at
Payment
----------------------------------------------------------------------------------------
id
name
tax
created_at
updated_at
This is a query I made.
SELECT t.id, t.user_id, u1.name, u1.email, v.code, t.amount, t.type, t.created_at, t.invoice_transaction, i.status, p.name,
FROM transactions AS t
INNER JOIN users AS u1 on u1.id = t.user_id
LEFT JOIN vouchers_transaction AS vt on vt.user_id = u1.id
LEFT JOIN vouchers AS v on v.id = vt.voucher_id
LEFT JOIN invoice AS i on i.order_data = t.invoice_transaction
LEFT JOIN payment AS p on p.id = i.payment_id
WHERE t.type = 'buy'
ORDER BY id ASC
In this case I managed to get the data I wanted. But the results of the query contained duplicate transaction id data such as:
Result
---------------------------------------------------------------------------------------------------------------------------
id user_id name email code amount type invoice_transaction status payment_name
1 1 John Doe John#mail.com ycqs1 150 buy SCS11DAS success bank
1 1 John Doe John#mail.com ycqs1 150 buy SCS11DAS success bank
2 1 John Doe John#mail.com n1ksa 200 buy SCS12DAS success bank
Update
It seems like this happened because in the transaction voucher table there is no connection with the transaction table.
Example:
Voucher Transaction
---------------------------------------------------------------------------------------------------------------------------
id user_id voucher_id
1 1 1
2 1 2
3 2 3
Then each transaction will duplicate according to the number of vouchers used in the transaction vouchers, both transactions that use vouchers or not.
I know the best way is to change the database schema. But in this case can it still be done in this case or not?
Results
Result
---------------------------------------------------------------------------------------------------------------------------
id user_id name email code amount type invoice_transaction status payment_name
1 1 John Doe John#mail.com ycqs1 150 buy SCS11DAS success bank
1 1 John Doe John#mail.com sa31a 150 buy SCS11DAS success bank
2 1 John Doe John#mail.com n1ksa 200 buy SCS12DAS success bank
How do I ignore the duplicated transaction id?
Try using group by
SELECT t.id, t.user_id, u1.name, u1.email, v.code, t.amount, t.type, t.created_at, t.invoice_transaction, i.status, p.name,
FROM transactions AS t
INNER JOIN users AS u1 on u1.id = t.user_id
LEFT JOIN vouchers_transaction AS vt on vt.user_id = u1.id
LEFT JOIN vouchers AS v on v.id = vt.voucher_id
LEFT JOIN invoice AS i on i.order_data = t.invoice_transaction
LEFT JOIN payment AS p on p.id = i.payment_id
WHERE t.type = 'buy'
GROUP BY SELECT t.id, t.user_id, u1.name, u1.email, v.code, t.amount, t.type, t.created_at, t.invoice_transaction, i.status, p.name
ORDER BY id ASC
You will always get double ID's because the rows are different. The code and amount columns are all unique and you havent told SQL what to do with those columns. The group by Mahesh showed will work, if you change it to resolve the difference in the code and amount columns.
what amount do you want to see for ID 1? The lowest? highest? average? sum?.
either you have to remove those 2 columns from the query, or provide an aggregate function to resolve what to show
SELECT DISTINCT ON column1, column2, ...
FROM table_name;
The SELECT DISTINCT ON statement is used to return only distinct (different) values.

Most popular pairs of shops for workers from each company

I've got 2 tables, one with sales and one with companies:
Sales Table
Transaction_Id Shop_id Sale_date Client_ID
92356 24234 11.09.2018 12356
92345 32121 11.09.2018 32121
94323 24321 11.09.2018 21231
94278 45321 11.09.2018 42123
Company table
Client_ID Company_name
12345 ABC
13322 ABC
32321 BCD
22221 BCD
What I want to achieve is distinct count of Clients from each Company for each pair of shops(Clients who had at least 1 transaction in both of shops) :
Shop_Id_1 Shop_id_2 Company_name Count(distinct Client_id)
12356 12345 ABC 31
12345 14278 ABC 23
14323 12345 BCD 32
14278 12345 BCD 43
I think that I have to use self join, but my queries even with filter for one week is killing DB, any thoughts on that? I'm using Microsoft SQL server 2012.
Thanks
I think this is a self-join and aggregation, with a twist. The twist is that you want to include the company in each sales record, so it can be used in the self-join:
with sc as (
select s.*, c.company_name
from sales s join
companies c
on s.client_id = c.client_id
)
select sc1.shop_id, sc2.shop_id, sc1.company_name, count(distinct sc1.client_id)
from sc sc1 join
sc sc2
on sc1.client_id = sc2.client_id and
sc1.company_name = sc2.company_name
group by sc1.shop_id, sc2.shop_id, sc1.company_name;
I think there are some issues with your question. I interpreted it as such that the company table contains the shop ID's, not the ClienId's.
First you can create a solution to get the shops as rows for each company. Here I chose a maximum of 5 shops per company. Don't forget the semicolon in the previous statement before the cte's.
WITH CTE_Comp AS
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY CompanyName ORDER BY ShopID) AS RowNumb
FROM Company AS C
)
SELECT C1.ShopID,
C2.ShopID AS ShopID_2,
C3.ShopID AS ShopID_3,
C4.ShopID AS ShopID_4,
C5.ShopID AS ShopID_5,
C1.CompanyName
INTO ShopsByCompany
FROM CTE_Comp AS C1
LEFT JOIN CTE_Comp AS C2 ON C1.CompanyName= C2.CompanyName AND RowNumb = 2
LEFT JOIN CTE_Comp AS C2 ON C1.CompanyName= C3.CompanyName AND RowNumb = 3
LEFT JOIN CTE_Comp AS C2 ON C1.CompanyName= C4.CompanyName AND RowNumb = 4
LEFT JOIN CTE_Comp AS C2 ON C1.CompanyName= C5.CompanyName AND RowNumb = 5
WHERE C1.RowNumb = 1
After that, in a few steps, I think you could get the desired result:
WITH ClientsPerShop AS
(
SELECT ShopID,
COUNT (DISTINCT ClientID) AS TotalClients
FROM Sales
GROUP BY ShopID
)
, ClienstsPerCompany AS
(
SELECT CompanyName,
SUM (TotalClients) AS ClientsPerComp
FROM Company AS C
INNER JOIN ClientsPerShop AS CPS ON C.ShopID = CPS.ShopID
GROUP BY CompanyName
)
SELECT *
FROM ClienstsPerCompany AS CPA
INNER JOIN ShopsByCompany AS SBC ON SBC.CompanyName = CPA.CompanyName
Hopefully this will bring you closer to your solution, best of luck!

Allow nulls / de-duplicate within multi-table join? T-SQL

I was wondering if there is a way in either SSIS or T-SQL (SQL Server 2012) to easily return non-duplicate data when doing a multi-table join (per-column, not per row)
I am trying to denormalize / flatten a bunch of data for conversion into a warehouse and I am winding up duplicating a ton of data. I'm hoping there is a sort of rollup/summary function or a design concept I am missing that can help me when merging multiple tables to a single destination.
Example
Let's say for example I have three tables: CUSTOMERS, CUSTOMER_ADDRESSES and CUSTOMER_ACCOUNTS. They and their data look like this:
CUSTOMERS
CUST_ID NAME
1 Burton Guster
CUSTOMER_ADDRESSES
CUST_ID ADDR_SEQ ADDRESS
1 1 123 Awesome St
1 2 456 Fake St
CUSTOMER_ACCOUNTS
CUST_ID ACCT_SEQ ACCT_TYPE ACCOUNT_OPEN_DT
1 1 TAP 1/1/1989
1 2 PHARMA 1/1/2010
I join them using a query like this:
SELECT a.CUST_ID, a.NAME, b.ADDRESS, c.ACCT_TYPE, c.ACCOUNT_OPEN_DT
FROM CUSTOMERS a
JOIN CUSTOMER_ADDRESSES b on a.CUST_ID = b.CUST_ID
JOIN CUSTOMER_ACCOUNTS c on a.CUST_ID = c.CUST_ID
Obviously each row joins to each row and as expected my output looks like this:
ID NAME ADDRESS ACCT_TYPE ACCT_OPEN_DT
1 Burton Guster 123 Awesome St TAP 1/1/1989
1 Burton Guster 123 Awesome St PHARMA 1/1/2010
1 Burton Guster 456 Fake St TAP 1/1/1989
1 Burton Guster 456 Fake St PHARMA 1/1/2010
Is there any way for me to get something like this instead?:
ID NAME ADDRESS ACCT_TYPE ACCT_OPEN_DT
1 Burton Guster 123 Awesome St TAP 1/1/1989
1 NULL 456 Fake St PHARMA 1/1/2010
The goal being to group each column, returning the distinct value per column only once. The larger set would be grouped by the customer ID.
Thank you
Sure, it can be done, although it's kinda awkward to do... :-)
You can use ROW_NUMBER() to get a running row number per costumer from each table independently. Then you can use these row numbers to bring the data together:
;WITH custCTE AS (
SELECT CUST_ID, NAME, 1 AS CUST_ROW_N
FROM CUSTOMERS
),
addrCTE AS (
SELECT CUST_ID, ADDRESS, ROW_NUMBER() OVER(PARTITION BY CUST_ID ORDER BY ADDR_SEQ) CUST_ROW_N
FROM CUSTOMER_ADDRESSES
),
acctCTE AS (
SELECT CUST_ID, ACCT_TYPE, ACCOUNT_OPEN_DT, ROW_NUMBER() OVER(PARTITION BY CUST_ID ORDER BY ACCT_SEQ) CUST_ROW_N
FROM CUSTOMER_ACCOUNTS
)
SELECT COALESCE(a.CUST_ID, b.CUST_ID, c.CUST_ID), a.NAME, b.ADDRESS, c.ACCT_TYPE, c.ACCOUNT_OPEN_DT
FROM custCTE a FULL JOIN addrCTE b ON
a.CUST_ID = b.CUST_ID AND a.CUST_ROW_N = b.CUST_ROW_N FULL JOIN acctCTE c ON
(b.CUST_ID = c.CUST_ID AND b.CUST_ROW_N = c.CUST_ROW_N) OR (a.CUST_ID = c.CUST_ID AND a.CUST_ROW_N = c.CUST_ROW_N)
Here's an SQLFiddle

Calculate value in the query by values from two tables

I have product table like this
PRODUCT_ID PACK_SIZE PACK_PRIZE
3000 5 2.5
3001 5 2.5
3002 5 2.5
3003 5 2.5
Order table
order_id client_id
75001 1024
75002 1033
75003 1030
ITEMS Table
ORDER_ID PRODUCT_ID NUMBER_ORDERED
75001 3936 2
75001 3557 5
75001 3012 3
75001 3236 4
Client Table
CLIENT_ID LAST_NAME STATUS
1021 Smith private
1022 Williams corporate
1023 Browne private
1024 Tinsell corporate
These are sample data I just added these just to show sample data.
I want to select top 2 private clients who has done the orders which are having higher values.
I have problem in selecting orders with max sold amount.
Here's what I'm trying to do.
In this I'm trying to get the Client IDS
SELECT CLIENTS.CLIENT_ID
FROM ORDERS
INNER JOIN ITEMS ON ORDERS.ORDER_ID=ITEMS.ORDER_ID
INNER JOIN PRODUCTS ON ITEMS.PRODUCT_ID =PRODUCTS.PRODUCT_ID
INNER JOIN CLIENTS ON ORDERS.CLIENT_ID = CLIENTS.CLIENT_ID
WHERE ( )
In this i'm trying to select top 2 orders
SELECT TOP 2 ORDERS.ORDER_ID FROM ORDERS
INNER JOIN ITEMS ON ORDERS.ORDER_ID=ITEMS.ORDER_ID
INNER JOIN PRODUCTS ON ITEMS.PRODUCT_ID =PRODUCTS.PRODUCT_ID
WHERE ((PRODUCTS.PACK_PRIZE/PRODUCTS.PACK_SIZE)*(ITEMS.NUMBER_ORDERED));
Gives me errors
FROM Key word not found where expected.
What I want to do is select the order ids from orders which are having highest total and which are not from same client, total should be calculated by finding the unit price by dividing pack_price from pack_size and multiplying it by number_ordered from the items table which is having the matching order id. The ordered clients should be corporate clients.
I'm using oracle 11g.
pack_prize is number pack_size is number
number_ordered is number data type
Oracle doesn't support top 2. Instead use rownum and a subquery:
WITH CTE as (
SELECT ORDERS.ORDER_ID, PRODUCTS.PACK_PRIZE, PRODUCTS.PACK_SIZE, ITEMS.NUMBER_ORDERED
FROM ORDERS INNER JOIN
ITEMS
ON ORDERS.ORDER_ID = ITEMS.ORDER_ID INNER JOIN
PRODUCTS
ON ITEMS.PRODUCT_ID = PRODUCTS.PRODUCT_ID
)
SELECT ORDER_ID
FROM (SELECT CTE.*
FROM CTE
ORDER BY (PACK_PRIZE/PACK_SIZE) * NUMBER_ORDERED DESC
) t
WHERE rownum <= 2;
I'm guessing that the strange where expression is what you are using to determine the best rows.
TOP does not work in oracle. You can use the virtual column ROWNUM or the function ROW_NUMBER() OVER() to get similar functionality.

Complex SQL Query - Joining 5 tables with complex conditions

I have the following tables: Reservations, Order-Lines, Order-Header, Product, Customer. Just a little explanation on each of these tables:
Reservations Contains "reservations" for a billing customer/product combination.
Order-Lines Contains line item detail for orders, including the product they ordered and the qty.
Order-Header Contains header info for orders including the date, customer and billing customer
Product Contains product detail information
Customer Contains Customer detail information.
Below are the tables with their associated fields and sample data:
Reservation
bill-cust-key prod-key qty-reserved reserve-date
10000 20000 10 05/30/2014
10003 20000 5 06/20/2014
10003 20001 15 06/20/2014
10003 20001 5 06/25/2014
10002 20001 5 06/21/2014
10002 20002 20 06/21/2014
Order-Item
order-num cust-key prod-key qty-ordered
30000 10000 20000 10
30000 10000 20001 5
30001 10001 20001 10
30002 10001 20001 5
30003 10002 20003 20
Order-Header
order-num cust-key bill-cust-key order-date
30000 10000 10000 07/01/2014
30001 10001 10003 07/03/2014
30002 10001 10003 07/15/2014
30003 10002 10002 07/20/2014
Customer
cust-key cust-name
10000 Customer A
10001 Customer B
10002 Customer C
10003 Customer D
Product
prod-key prod-name
20000 Prod A
20001 Prod B
20002 Prod C
20003 Prod D
I am attempting to write a query that will show me customer/product combinations that exist in both the reservation and order-item tables. A little snafu is that we have a customer and a billing customer. The reservation and order-header tables contain both the customers, but the order-item table only contains the customer. The results should display the billing customer. Additionally, there can be several reservations and order-items for the same customer/product combination, so I would like to show a total sum of the qty-reserved and the qty-ordered.
Below is an example of my desired output:
bill-cust-key cust-name prod-key prod-name qty-ordered qty-reserved
10000 Customer A 20000 Prod A 10 10
10003 Customer D 20001 Prod B 15 20
This is the query that I have tried and doesn't seem to be working for me.
SELECT customer.cust-key, customer.cust-name, product.prod-key, prod.prod-name,
SUM(order-item.qty-ordered), SUM(reservation.qty-reserved)
FROM ((reservation INNER JOIN order-item on reservation.prod-key = order-item.product-key)
INNER JOIN order-header on reservation.bill-cust-key = order-header.bill-cust-key and
order-item.order-num = order-header.order-num), customer, product
WHERE customer.cust-key = reservation.bill-cust-key
AND product.prod-key = reservation.prod-key
GROUP BY customer.cust-key, customer.cust-name, product.prod-key, product.prod-name
I'm sorry for such a long post! I just wanted to make sure that I had my bases covered!
You want to join your tables like this:
from reservation res join order-header oh on res.bill-cust-key = oh.bill-cust-key
join order-item oi on oi.order-num = oh.order-num
and oi.prod-key = res.prod-key
/* join customer c on c.cust-key = oi.cust-key old one */
join customer c on c.cust-key = oh.bill-cust-key
join product p on p.prod-key = oi.prod-key
I find that it can be very helpful to separate out your output rows from your aggregate rows by using CROSS APPLY (or OUTER APPLY) or simply an aliased inner query if you don't have access to those.
For example,
SELECT
customer.cust-key,
customer.cust-name,
tDetails.prod-key,
tDetails.prod-name,
tDetails.qty-ordered,
tDetails.qty-reserved
FROM customer
--note that this could be an inner-select table in which you join if not cross-join
CROSS APPLY (
SELECT
product.prod-key,
prod.prod-name,
SUM(order-item.qty-ordered) as qty-ordered,
SUM(reservation.qty-reserved) as qty-reserved
FROM reservation
INNER JOIN order-item ON reservation.prod-key = order-item.product-key
INNER JOIN product ON reservation.prod-key = product.prod-key
WHERE
reservation.bill-cust-key = customer.cut-key
GROUP BY product.prod-key, prod.prod-name
) tDetails
There are many ways to slice this, but you started out the right way saying "what recordset do I want returned". I like the above because it helps me visualize what each 'query' is doing. The inner query marked by the CROSS apply is simply grouping by prod orders and reservations but is filtering by the current customer in the outer top-most query.
Also, I would keep joins out of the 'WHERE' clause. Use the 'WHERE' clause for non-primary key filtering (e.g. cust-name = 'Bob'). I find it helps to say that one is a table join, the 'WHERE' clause is a property filter.
TAKE 2 - using inline queries
This approach still tries to get a list of customers with distinct products, and then uses that data to form the outer query from which you can get aggregates.
SELECT
customer.cust-key,
customer.cust-name,
products.prod-key,
products.prod-name,
--aggregate for orders
( SELECT SUM(order-item.qty-ordered)
FROM order-item
WHERE
order-item.cust-key = customer.cust-key AND
order-item.prod-key = products.prod-key) AS qty-ordered,
--aggregate for reservations
( SELECT SUM(reservation.qty-reserved)
FROM reservations
--join up billingcustomers if they are different from customers here
WHERE
reservations.bill-cust-key = customer.cust-key AND
reservations.prod-key = products.prod-key) AS qty-reserved
FROM customer
--get a table of distinct products across orders and reservations
--join products table for name
CROSS JOIN (
SELECT DISTINCT order-item.prod-key FROM order-item
UNION
SELECT DISTINCT reservation.prod-key FROM reservations
) tDistinctProducts
INNER JOIN products ON products.prod-key = tDistinctProducts.prod-key
TAKE 3 - Derived Tables
According to some quick googling, Progress DB does support derived tables. This approach has largely been replaced with CROSS APPLY (or OUTER APPLY) because you don't need to do the grouping. However, if your db only supports this way then so be it.
SELECT
customer.cust-key,
customer.cust-name,
products.prod-key,
products.prod-name,
tOrderItems.SumQtyOrdered,
tReservations.SumQtyReserved
FROM customer
--get a table of distinct products across orders and reservations
--join products table for name
CROSS JOIN (
SELECT DISTINCT order-item.prod-key FROM order-item
UNION
SELECT DISTINCT reservation.prod-key FROM reservations
) tDistinctProducts
INNER JOIN products ON products.prod-key = tDistinctProducts.prod-key
--derived table for order-items
LEFT OUTER JOIN ( SELECT
order-item.cust-key,
order-item.prod-key,
SUM(order-item.qty-ordered) AS SumQtyOrdered
FROM order-item
GROUP BY
order-item.cust-key,
order-item.prod-key) tOrderItems ON
tOrderItems.cust-key = customer.cust-key AND
tOrderItems.prod-key = products.prod-key
--derived table for reservations
LEFT OUTER JOIN ( SELECT
reservations.bill-cust-key,
reservations.prod-key,
SUM(reservations.qty-reserved) AS SumQtyReserved
FROM reservations
--join up billingcustomers if they are different from customers here
WHERE
reservations.bill-cust-key = customer.cust-key AND
reservations.prod-key = products.prod-key) tReservations ON
tReservations.bill-cust-key = customer.cust-key AND
tReservations.prod-key = products.prod-key
Based on your original code and request, here's the starting point of a Progress solution -
DEFINE VARIABLE iQtyOrd AS INTEGER NO-UNDO.
DEFINE VARIABLE iQtyReserved AS INTEGER NO-UNDO.
FOR EACH order-item
NO-LOCK,
EACH order-header
WHERE order-header.order-num = order-item.order-num
NO-LOCK,
EACH reservation
WHERE reservation.prod-key = order-item.prod-key AND
reservation.bill-cust-key = order-header.bill-cust-key
NO-LOCK,
EACH product
WHERE product.prod-key = reservation.prod-key
NO-LOCK,
EACH customer
WHERE customer.cust-key = reservation.bill-cust-key
NO-LOCK
BREAK BY customer.cust-key
BY product.prod-key
BY product.prod-name
:
IF FIRST-OF(customer.cust-key) OR FIRST-OF(product.prod-key) THEN
ASSIGN
iQtyOrd = 0
iQtyReserved = 0
.
ASSIGN
iQtyOrd = iQtyOrd + reservation.qty-ordered
iQtyReserved = iQtyReserved + reservation.qty-reserved
.
IF LAST-OF(customer.cust-key) OR LAST-OF(product.prod-key) THEN
DISPLAY
customer.cust-key
customer.cust-name
product.prod-key
prod.prod-name
iQtyOrd
iQtyReserved
WITH FRAME f-qty
DOWN
.
END.