Database Toolbox |
|
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
- From the Fields list box, select the entry whose value you want to restrict.
- Define the Condition for the selected field. For more information, see Condition as described for where clauses.
- Select an Operator to add another condition. For more information, see Operator as described for where clauses.
- Click Apply to create the clause.
- The subquery appears in the Current clauses area.
- Repeat steps 1 through 4 to add more conditions.
- You can change the clauses.
- To edit a clause, select it from the Current clauses area and click Edit. Make changes to Fields, Condition, and Operator fields, and click Apply.
- To group clauses so that they are evaluated as a whole, select the clauses from Current clauses. Use Ctrl+click or Shift+click to select multiple clauses. Then click Group. Parentheses are added around the set of clauses. To ungroup clauses, select the clauses and then click Ungroup. For more information, see Grouping Criteria in the Visual Query Builder documentation.
- To delete a clause, select it from the Current clauses area and click Delete. Use Ctrl+click or Shift+click to select multiple clauses to delete.
- You can specify a subquery in the Having Clauses dialog box. For more information, see Subquery for Where clauses.
- Click OK.
- 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:
- In the Visual Query Builder dialog box Advanced query options area, click Having.
- The Having Clauses dialog box appears.
- 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).
- Click OK.
- The Having Clauses dialog box closes. The SQL statement in the Visual Query Builder dialog box reflects the having clause you specified.
- Assign a MATLAB workspace variable and click Execute to run the query.
- 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
| Group By | | Order By | |
© 1994-2005 The MathWorks, Inc.