1. A method for estimating a selectivity of a HAVING clause in an SQL query, the method comprising the steps of: a) calculating a selectivity estimate for the HAVING clause for each member in a selected sample set of group sizes; and b) using the selectivity estimate for the members of the sample set of group sizes to define the selectivity of the HAVING clause to be a weighted estimate calculated to represent the selectivity for the possible number of groups for the possible number of groups for the HAVING clause.