HP c-tree-SQL ISQL and Tools manual Example 3-4 Specifying Column Breaks and Values with Display

Page 34

ISQL and Tools

whenever the value in the customer_name column changes. In other words, we need to specify a column break on the customer_name column.

Approach this task in two steps. First, devise a DISPLAY statement to display the customer name and confirm that it is displaying correctly. Then, issue COMPUTE statements to calcu- late the statistics for each customer (namely, the count and sum of orders), and add DISPLAY statement to include those statistics. All of the DISPLAY, COMPUTE and BREAK statements have to specify the same break to get the desired results.

The following example shows the DISPLAY and BREAK statements that display the customer name. The COL clause in the DISPLAY statement indents the display slightly to emphasize the change in presentation.

The following example uses the column formatting from previous examples. Notice that the column formatting also affects DISPLAY statements that specify the same column.

Example 3-4: Specifying Column Breaks and Values with DISPLAY

ISQL> display col 5

"Summary of activity for", customer_name on customer_name;

ISQL> break on customer_name

 

 

ISQL> select c.customer_name, c.customer_city, o.order_id, o.order_value

from customers c, orders o

 

 

where o.customer_id = c.customer_id

 

 

order by c.customer_name;

 

 

CUSTOMER_NAME

CUSTOMER_CITY

ORDER_ID

ORDER_VALUE

-------------

-------------

--------

-----------

Aerospace Enterpris

Scottsdale

13

$3,000,000.00

Aerospace Enterpris

Scottsdale

14

$1,500,000.00

Summary of activity for Aerospace Enterpris

 

Chemical Constructi

Joplin

11

$3,000,000.00

Chemical Constructi

Joplin

12

$7,500,000.00

Summary of activity for Chemical Constructi

 

Luxury Cars Inc.

North Ridgeville

21

$6,000,000.00

Luxury Cars Inc.

North Ridgeville

20

$5,000,000.00

Summary of activity for Luxury Cars Inc.

.

.

.

Next, issue two COMPUTE statements to calculate the desired summary values.

COMPUTE statements specify an SQL aggregate function (AVG, MIN, MAX, SUM, or COUNT), a column name, a variable name, and a break specification. ISQL applies the aggre- gate function to all values of the column for the set of rows that corresponds to the break spec- ification. It stores the result in the variable, which subsequent DISPLAY statements can use to display the result.

For this example, you need two separate compute statements. One calculates the number of orders (COUNT OF the order_id column) and the other calculates the total cost of orders (SUM OF the order_value column). Both specify the same break, namely, customer_name. The following example shows the COMPUTE statements, which store the resulting value in the variables num_orders and tot_value.

3-8

FairCom Corporation

Image 34
Contents Isql and Tools Reference Guide For use with c-treeSQL ServerPage Table of Contents Data Load Utility dbload Tutorial Source Code IiiFairCom Corporation Purpose of this Manual Syntax Diagram ConventionsDocumentation Overview AudienceRelated Documentation Isql and ToolsIntroduction OverviewIsql and Tools FairCom Corporation Init Quick TourIntroductory Tutorial IsqlIsql Create Table Custmast DefineManage Isql Commit Work CustmastComplete Introductory Tutorial Code DoneQuick Tour Relational Model and Indexing Tutorial ISQLTutorial2.sqlQuick Tour Values Insert Into Insert IntoValues Commit Work QTY PriceComplete Relational Model and Indexing Tutorial Source Code Locking Tutorial ISQLTutorial3.sql@ISQL @iSQLTutorial3.sql Isql Delete from Custmast Complete Locking Tutorial Source Code Transaction Processing Tutorial ISQLTutorial4.sqlTransaction Rollback Work Complete Transaction Processing Tutorial Source Code Syntax Isql StatementsStarting Interactive SQL ArgumentsUsername PasswordStatement History Support ConnectstringIsql Statements for Statement History Support Formatting Output of Isql QueriesIsql Statements Statement SummaryIsql Statements for Query Formatting Summary DisplayExample 3-1 Unformatted Query Display from Isql Customername Customercity Orderid OrdervalueFormatting Column Display with the Column Statement Example 3-2 Controlling Display Width of Character ColumnsOrdervalue Example 3-3 Customizing Format of Numeric Column DisplaysCustomername Customercity Example 3-4 Specifying Column Breaks and Values with Display Numorders Customername Example 3-6 Specifying a Query Header and Footer with Title Help and Table Statements Transaction SupportDescription Isql Reference1 @ Execute Syntax ExampleBreak Syntax BreakspecSkip n ExamplesCustomername Clear Syntax HistoryOption ArgumentColumn Syntax Break Column Compute Display TitleFormat formatstring ColumnnameHeading headingtext Date-Time Format Strings for the Column Statement Character DescriptionNot Null INT Null ? Type Length ColnameChar Amount OrderinfoSysdate NEW Title FLDColumn Title ComputeAVG MAX MIN SUM Count VariablenameDefine Syntax ValueCOL columnnumber ColpositionDisplayvalue @columnnameEdit Syntax Related Statements Exit or Quit SyntaxExit 10 GET Syntax Isql GET query.sqlIsql RUN History Syntax Help CommandsclausesHelp Syntax Orderstate LotlocationFollowing example illustrates usage of the History statement Host or SH or Syntax HostcommandFrom List Syntax Quit Quit or Exit Syntax16 RUN Syntax Isql HistoryPagesize Save Syntax18 SET Syntax LinesizePagesize numberlines Isql Break on Isql Select TBL from Systables TBL Connection databasename DefaultTransaction Isolation Level isolationlevel TBLShow Syntax Filename on Is Default ?Spool Syntax Database ConnectionsIsql Spool STK on Start SyntaxArgument … Isql Spool OFFNull ? Type Length Colname Not Null INT Not Null VarcharType Length Colname Null ? TablenameDate Text Title SyntaxLeft Center Right COL n DoubleIsql Clear Title Isql and Tools FairCom Corporation Data Load Utility dbload IntroductionPrerequisites for Dbload Dbload Command Line SyntaxCommandsfile OptionsData File Formats Data Load Utility dbloadFixed Length Records Commands FileVariable Length Records Next RecordDefine Record Statement Char Short Long Float DoubleFor Each Statement NullExample 4-1 Sample dbload commands files ExamplesRecord name redefined Compilation ErrorsPosition not specified for fixed length record Fatal Errors Isql and Tools FairCom Corporation Data Unload Utility dbdump Prerequisites for DbdumpDbdump Command Line Syntax Data Unload Utility dbdump Short Long Float DoubleFor Record Statement Define Record custrec of Fixed Length 37 AS Isql and Tools FairCom Corporation Schema Export Utility dbschema Username.tablename Username.procedurenameOutfile Username.triggernameImport Begin Schema Export Utility dbschemaDbschema ENDIsql and Tools FairCom Corporation Tutorial Source Code Commit Work Select * from Custmast Delete from CustmastMoney IntegerVARCHAR6 Tutorial Source Code Commit Work Delete from CustmastImdesc VARCHAR48 Select * from orderlist Select * from orderitems Isql and Tools FairCom Corporation Symbols Index-iIsql Index-ii FairCom CorporationIndex Index-iii FairCom Corporation