Re: Most common entry in MySQL field
| From: | Folke Ashberg | Date: | Sat, 25 Nov 2000 20:52:34 +0000 |
| Subject: | Re: Most common entry in MySQL field | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27180@lists.php.net to get a copy of this message | ||
Oh, sorry!
The following examples should be the right:
select gid,count(*) as maximal from user
group by gid
order by maximal desc
limit 5;
regards
Folke
--
Folke Ashberg
Stage Internet Services GmbH
Technical Development
folke@fanstage.de
folke@fanstage.de | Tel: +49 89 454591-77 | Fax: +49 89 454591-71
Kreillerstr. 21 | 81673 Munich | Germany | www.fanstage.de
On Sat, 25 Nov 2000, Tyler Longren wrote:
> No I mean the 5 most common entries. Not the 5 fields with the highest
> value.
>
> I want to get the 5 most common entries in one field.
> Example:
>
> Linux: 100
> BSD: 40
> PHP: 70
> MySQL: 80
> Tyler: 90
> Vectra: 20
> IRQ: 10
>
> That means Linux is in the field 100 times, BSD is in the field 40 times,
> PHP is in the field 70 times, and so on...
>
> So, I want to grab the 5 most common entries, which would be Linux, then
> Tyler, then MySQL, then PHP, then BSD. And Vectra and IRQ wouldn't even be
> displayed.
>
> Is that a better explanation?
>
> Thanks,
> Tyler
>
> On Sat, 25 Nov 2000, Folke Ashberg wrote:
> > Date: Sat, 25 Nov 2000 21:44:19 +0100 (CET)
> > To: Tyler Longren <tyler.longren@midiowa.net>
> > From: Folke Ashberg <folke@fanstage.de>
> > CC: PHP-General <php-general@lists.php.net>
> > Subject: Re: [PHP] Most common entry in MySQL field
> >
> > Do you mean the 5 fields with the hightest value?
> >
> > then you should use
> >
> > select max(the_field) as maximal from user group by uid
> > order by maximal desc
> > limit 5;
> >
> > regards
> > Folke
> >
> >
> > --
> > Folke Ashberg
> >
> > Stage Internet Services GmbH
> > Technical Development
> > folke@fanstage.de
> >
> > folke@fanstage.de | Tel: +49 89 454591-77 | Fax: +49 89 454591-71
> > Kreillerstr. 21 | 81673 Munich | Germany | www.fanstage.de
> >
> > On Sat, 25 Nov 2000, Tyler Longren wrote:
> >
> > > Hello,
> > >
> > > This is probably more towards the SQL side, but how could I get the 5
> > most
> > > common entries in a MySQL field?
> > >
> > > Thanks,
> > > Tyler Longren
> > >
> > >
> > >
> >
>
>