Database Toolbox Previous page   Next Page

Having

Use the Having function to refine the results of a Group By clause.

After specifying a group-by clause in the Advanced query options of the Visual Query Builder dialog box, click Having. The Having Clauses dialog box appears.

Having Clauses Dialog Box

  1. From the Fields list box, select the entry whose value you want to restrict.
  2. Define the Condition for the selected field. For more information, see Condition as described for where clauses.
  3. Select an Operator to add another condition. For more information, see Operator as described for where clauses.
  4. Click Apply to create the clause.
  1. The subquery appears in the Current clauses area.

  1. Repeat steps 1 through 4 to add more conditions.
  2. You can change the clauses.
  3. You can specify a subquery in the Having Clauses dialog box. For more information, see Subquery for Where clauses.
  4. Click OK.
  1. The Having Clauses dialog box closes. The SQL statement in the Visual Query Builder dialog box reflects the having clause.

Example Using Having Clause

This example restricts the results from Example Using Group By Clauses to sales greater than 2000 for January and February:

  1. In the Visual Query Builder dialog box Advanced query options area, click Having.
  1. The Having Clauses dialog box appears.

  1. For January, select > as the Relation Condition, type 2000 as the Relation value, select the AND Operator, and click Apply. For February, select > as the Relation Condition, type 2000 as the Relation value, and click Apply (shown below).

  2. Click OK.
  1. The Having Clauses dialog box closes. The SQL statement in the Visual Query Builder dialog box reflects the having clause you specified.

  1. Assign a MATLAB workspace variable and click Execute to run the query.

  2. Compare these results, which were refined using Having, to those from the Example Using Group By Clauses (shown below as B), which did not refine the results.

See Also


Previous page  Group By Order By Next page

© 1994-2005 The MathWorks, Inc.