count in where clause

Results 1 to 2 of 2

Thread: count in where clause

  1. #1
    Join Date
    Dec 1969

    Default count in where clause

    I wrote a query to get country and noofstudents like this.<BR><BR><BR>SELECT COUNTRY, COUNT(Studentid) AS numberofStudents<BR>FROM students GROUP BY country<BR><BR>Now i have to write a query which results only country where noofstudents (COUNT(Studentid)) greaterthan 10.<BR><BR>how can i use count() in where clause. <BR><BR>Any help is much appreciated.<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default You can't use the WHERE clause...

    ...for an aggregate function (Count() is an aggregate function). You&#039;ll have to use HAVING instead. Check out for some tutorials. It&#039;ll be something like:<BR><BR>SELECT MyField, Count(MyOtherField) FROM MyTable GROUP BY MyField HAVING Count(MyOtherField) &#062; 10<BR><BR>Oliver.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts