Suppose we have a table "Person" as below and we need to find out the frequency of each age.
| Id | LastName | FirstName | Age | City |
| 1 | Smith | John | 33 | Newyork |
| 2 | Smith | Mike | 34 | Boston |
| 3 | Paul | Ryan | 39 | Chicago |
| 4 | William | Brian | 45 | Baltimore |
| 5 | Rao | Sunita | 41 | Dayton |
| 6 | Zing | Sue | 33 | Owings Mills |
| 7 | Smith | Robert | 45 | Newyork |
| 8 | Paul | Zean | 33 | Chicago |
| 9 | Srivastava | Hemant | 33 | Baltimore |
| 10 | Rao | Venkat | 45 | Dayton |
We could find out the frequency distribution by following the SQL query.
SELECT
Age,
COUNT(Age) AS Frequency
FROM
Persons
GROUP BY
Age
ORDER BY
COUNT(Age) DESC

Hemant SrivastavaPosted Oct 17, 2012, 11:02 AM
@Heiko... Thanks.. In that case, we could use HAVING clause... For more detail, you may go to my blog: http://hemant-srivastava.blogspot.com/2012/10/sql-query-to-find-out-frequency-of-each.html
Heiko ScholzePosted Oct 17, 2012, 4:24 AM
Thanks for this query. But what must I do if I only need ages which have a count > 3? I tried to use a where clause but I get an error "ORA-00934: group function is not allowed here". Can you show me the solution?
Sumit Kumar SinhaPosted Oct 17, 2012, 4:05 AM
it's useful for me