SQL/MP Report Writer Guide
Table Of Contents
- What’s New in This Manual
- About This Manual
- 1 Introduction to the NonStop SQL/MP Report Writer
- 2 Using SQLCI and the Report Writer
- 3 Selecting Data for a Report
- 4 Customizing a Report
- Defining the Layout
- Specifying the Items in a Detail Line
- Naming Select List and Detail Line Items
- Organizing Rows Into Break Groups
- Labeling Information
- Formatting Data Values
- Formatting Dates and Times
- Using TACL to Pass Parameters
- Conditional Printing of Items or Line Entries
- Redefining Special Characters
- Calculating Totals
- Calculating Subtotals
- Printing Double-Byte Characters
- A Comparison of the Report Writer and the Enform Language
- Index
Selecting Data for a Report
HP NonStop SQL/MP Report Writer Guide—527213-001
3-29
Using Subqueries
+> WHERE PARTNUM = 2003);
S> LIST ALL;
SUPPNUM PARTNUM PARTCOST
------- ------- --------
2 2003 1400.00
10 2003 1450.00
--- 2 row(s) selected.
>>
This query finds all suppliers who charge more than the minimum price for part number
2003. The subquery is evaluated once to determine the minimum cost for the part.
Each row selected by the main query is compared to the result of the subquery.
You can replace the numeric literal 2003 with the parameter ?PART to create a
general query for gathering this information for any part.
The following commands illustrate a correlated query which finds suppliers whose price
exceeds the average price for a part:
>> SELECT SUPPNUM, PARTNUM, PARTCOST
+> FROM INVENT.PARTSUPP XP
+> WHERE PARTCOST > (SELECT AVG(PARTCOST)
+> FROM INVENT.PARTSUPP P
+> WHERE XP.PARTNUM = P.PARTNUM)
+> ORDER BY SUPPNUM;
S> LIST ALL;
SUPPNUM PARTNUM PARTCOST
------- ------- --------
1 212 2000.00
1 244 2400.00
1 255 3300.00
1 2405 500.00
2 2001 750.00
2 2003 1400.00
. . .
. . .
15 4102 21.00
--- 18 row(s) selected.
>>
The subquery is evaluated for each row selected by the main query. The FROM clause
of the main query defines the correlation name XP for the PARTSUPP table. The
subquery defines the correlation name P for the PARTSUPP table. The WHERE
clause defines the correlation. The subquery averages rows from the PARTSUPP table
with a PARTNUM value equal to the PARTNUM value of the current row from the outer
query.
You do not have to define a correlation name for both the main query and subquery in
order to perform this operation. You could use the implicit correlation name in the outer
query.