[thelist] MySQL COUNT() question

Matt Warden mwarden at gmail.com
Mon Nov 14 19:52:46 CST 2005

Hash: SHA1

Aron Lurie wrote:
> Hey, I have a MySQL problem that is posing a severe challenge to me regarding COUNT().
> Right now I have the following code:
> select CONCAT(fpe.fname,' ',fpe.lname) fullname, 
>  pe.alias, 
>  fce.Course,
>  COUNT(*) student_num 
> from f05people fpe,
>  f05classes fce, 
>  people pe,
>  f05studentsched fss 
> where pe.hcid=fpe.hcid 
>  and pe.alias=fce.Faculty 
>  and fpe.Faculty='Yes' 
>  and fce.Branch='HC-Tuesday' 
>  and fce.period='1' 
>  and fss.period='1' 
>  and fss.branch='HC-Tuesday' 
>  and fss.teacher = pe.alias 
>  group by fss.branch, fss.teacher,fss.period order by fce.Faculty ASC;
> This works fine so far returning all the values I want, however...
> The problem is that I want another COUNT(*) column that is grouped by a different set of fields in a different table. Is there a way to have two group by statements? How would I do this?

Not like that, no.

What count do you want? If it is truly separate from this query, you
need another query. However, if it is a field in this query, we can
probably come up with a solution for you.

- --
Matt Warden
Miami University
Oxford, OH, USA

This email proudly and graciously contributes to entropy.
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org


More information about the thelist mailing list