HP c-tree-SQL ISQL and Tools manual AVG MAX MIN SUM Count, Variablename

Page 48

ISQL and Tools

COMPUTE statements have no effect until you issue a BREAK statement with the same break_spec.

Issuing the COMPUTE statement without any arguments displays the currently-set COM- PUTE specifications, if any.

Arguments

AVG MAX MIN SUM COUNT

The function to apply to values of column_name. The functions AVG, MAX, MIN, and SUM can be used only when the column is numeric. The function COUNT can be used for any col- umn type.

column_name

The column whose value is to be computed. The column specified in column_name must also be included in the select list of the query. If column_name is not also included in the select list, it has no effect.

variable_name

Specifies the name of the variable where the computed value is stored. ISQL issues an implicit DEFINE statement for variable_name and assigns the variable a value of zero. During query processing, the value of variable_name changes as ISQL encounters the specified breaks.

break_spec

Specifies the set of rows after which ISQL processes the COMPUTE statement. A COMPUTE statement has no effect until you issue a corresponding BREAK statement. See the description of the BREAK statement in Section 3.7.2 "BREAK" on page 3-13 for details.

Examples

The following example computes the number of items ordered by each customer.

ISQL> break on customer_name

ISQL> display col 5 "Number of orders placed by", customer_name, "=", n_ord on customer_name

ISQL> compute count of order_id in n_ord on customer_name;

ISQL> select c.customer_name, o.order_id from customers c, orders o where o.customer_id = c.customer_id;

CUSTOMER_NAME

 

ORDER_ID

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

 

--------

Sports Cars Inc.

 

1

Sports Cars Inc.

 

2

Number of orders placed by Sports Cars Inc.

 

=

2

 

Mighty Bulldozer Inc.

3

Mighty Bulldozer Inc.

4

Number of orders placed by Mighty Bulldozer Inc.

 

=2

.

.

.

3-22

FairCom Corporation

Image 48
Contents Isql and Tools Reference Guide For use with c-treeSQL ServerPage Table of Contents Data Load Utility dbload Tutorial Source Code IiiFairCom Corporation Syntax Diagram Conventions Documentation OverviewPurpose of this Manual AudienceRelated Documentation Isql and ToolsIntroduction OverviewIsql and Tools FairCom Corporation Quick Tour Introductory TutorialInit IsqlDefine ManageIsql Create Table Custmast Isql Commit Work CustmastDone Complete Introductory Tutorial CodeQuick Tour Relational Model and Indexing Tutorial ISQLTutorial2.sqlQuick Tour Insert Into Values 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 Isql Statements Starting Interactive SQLSyntax ArgumentsPassword Statement History SupportUsername ConnectstringFormatting Output of Isql Queries Isql StatementsIsql Statements for Statement History Support 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 ColumnsExample 3-3 Customizing Format of Numeric Column Displays OrdervalueCustomername 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 SupportIsql Reference 1 @ Execute SyntaxDescription ExampleBreak Syntax BreakspecExamples Skip nCustomername Clear Syntax HistoryArgument Column SyntaxOption Break Column Compute Display TitleColumnname Format formatstringHeading headingtext Date-Time Format Strings for the Column Statement Character DescriptionNull ? Type Length Colname Not Null INTChar Orderinfo AmountSysdate FLD Column TitleNEW Title ComputeAVG MAX MIN SUM Count VariablenameDefine Syntax ValueColposition DisplayvalueCOL columnnumber @columnnameEdit Syntax Exit or Quit Syntax Related StatementsExit 10 GET Syntax Isql GET query.sqlIsql RUN Help Commandsclauses Help SyntaxHistory Syntax Orderstate LotlocationFollowing example illustrates usage of the History statement Hostcommand Host or SH or SyntaxFrom List Syntax Quit or Exit Syntax 16 RUN SyntaxQuit Isql HistorySave Syntax 18 SET SyntaxPagesize LinesizePagesize numberlines Connection databasename Default Transaction Isolation Level isolationlevelIsql Break on Isql Select TBL from Systables TBL TBLShow Syntax Is Default ? Spool SyntaxFilename on Database ConnectionsStart Syntax Argument …Isql Spool STK on Isql Spool OFFNull ? Type Length Colname Not Null INT Not Null VarcharTablename Type Length Colname Null ?Date Title Syntax Left Center Right COL nText DoubleIsql Clear Title Isql and Tools FairCom Corporation Data Load Utility dbload IntroductionDbload Command Line Syntax CommandsfilePrerequisites for Dbload OptionsData File Formats Data Load Utility dbloadCommands File Variable Length RecordsFixed Length Records Next RecordDefine Record Statement Char Short Long Float DoubleFor Each Statement NullExample 4-1 Sample dbload commands files ExamplesCompilation Errors Record name redefinedPosition 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.procedurename OutfileUsername.tablename Username.triggernameSchema Export Utility dbschema DbschemaImport Begin ENDIsql and Tools FairCom Corporation Tutorial Source Code Commit Work Select * from Custmast Delete from CustmastInteger MoneyVARCHAR6 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