pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: count different values in column
7+ messages / 7 participants
[nested] [flat]

* count different values in column?
@ 2002-04-19 09:27 Thorsten Wenzlaff <thorsten.wenzlaff@gmx.de>
  2002-04-20 17:23 ` Re: count different values in column? Rajesh Kumar Mallah <mallah@trade-india.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Thorsten Wenzlaff @ 2002-04-19 09:27 UTC (permalink / raw)
  To: pgsql-sql

Hello,
today I have a new question :)

I've a resulttable is generated by a couple of subselects and joins which
contains only one column.

Now I want to count the different values in the column.

Resulttable :
   a
------
10
12
12
12
14
14
15

I need the value which is repeated most in the resulttable (in this example
12 ) !


Any suggestions ?


Thx
berger




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: count different values in column?
  2002-04-19 09:27 count different values in column? Thorsten Wenzlaff <thorsten.wenzlaff@gmx.de>
@ 2002-04-20 17:23 ` Rajesh Kumar Mallah <mallah@trade-india.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Rajesh Kumar Mallah @ 2002-04-20 17:23 UTC (permalink / raw)
  To: Thorsten Wenzlaff <thorsten.wenzlaff@gmx.de>; +Cc: pgsql-sql



Does the below solve your problem ?


SELECT a  from  resulttable group by a order by count(a)  desc limit 1;
 a
----
 12
(1 row)

regds
mallah




Thorsten Wenzlaff wrote:

> Hello,
> today I have a new question :)
>
> I've a resulttable is generated by a couple of subselects and joins which
> contains only one column.
>
> Now I want to count the different values in the column.
>
> Resulttable :
>    a
> ------
> 10
> 12
> 12
> 12
> 14
> 14
> 15
>
> I need the value which is repeated most in the resulttable (in this example
> 12 ) !
>
> Any suggestions ?
>
> Thx
> berger
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* count different values in column
@ 2002-04-19 09:30 Albrecht Berger <berger1517@gmx.ch>
  1970-01-01 00:00 ` Re: count different values in column Christoph Haller <ch@rodos.fzk.de>
  2002-04-19 09:40 ` Re: count different values in column Tod McQuillin <devin@spamcop.net>
  2002-04-19 10:00 ` Re: count different values in column Gautham S. Rao <gautam.rao@tatainfotech.com>
  0 siblings, 3 replies; 7+ messages in thread

From: Albrecht Berger @ 2002-04-19 09:30 UTC (permalink / raw)
  To: pgsql-sql

Hello,
today I have a new question :)

I've a resulttable is generated by a couple of subselects and joins which
contains only one column.

Now I want to count the different values in the column.

Resulttable :
   a
------
10
12
12
12
14
14
15

I need the value which is repeated most in the resulttable (in this example
12 ) !


Any suggestions ?


Thx
berger





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: count different values in column
  2002-04-19 09:30 count different values in column Albrecht Berger <berger1517@gmx.ch>
@ 1970-01-01 00:00 ` Christoph Haller <ch@rodos.fzk.de>
  2 siblings, 0 replies; 7+ messages in thread

From: Christoph Haller @ 1970-01-01 00:00 UTC (permalink / raw)
  To: berger1517@gmx.ch; +Cc: pgsql-sql

select max(count) from (
select a, count(a) from Resulttable group by a 
) as foo; 
 max
-----
   3
(1 row)
should do it. 
Regards, Christoph 

> Hello,
> today I have a new question :)
> 
> I've a resulttable is generated by a couple of subselects and joins which
> contains only one column.
> 
> Now I want to count the different values in the column.
> 
> Resulttable :
>    a
> ------
> 10
> 12
> 12
> 12
> 14
> 14
> 15
> 
> I need the value which is repeated most in the resulttable (in this example
> 12 ) !
> 
> 
> Any suggestions ?
> 
> 
> Thx
> berger
> 



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: count different values in column
  2002-04-19 09:30 count different values in column Albrecht Berger <berger1517@gmx.ch>
@ 2002-04-19 09:40 ` Tod McQuillin <devin@spamcop.net>
  2002-04-19 09:55   ` Re: count different values in column Fduch the Pravking <fduch@antar.bryansk.ru>
  2 siblings, 1 reply; 7+ messages in thread

From: Tod McQuillin @ 2002-04-19 09:40 UTC (permalink / raw)
  To: Albrecht Berger <berger1517@gmx.ch>; +Cc: pgsql-sql

On Fri, 19 Apr 2002, Albrecht Berger wrote:

> Now I want to count the different values in the column.
>
> Resulttable :
>    a
> ------
> 10
> 12
> 12
> 12
> 14
> 14
> 15
>
> I need the value which is repeated most in the resulttable (in this example
> 12 ) !

SELECT a, count(a) FROM resulttable GROUP BY a ORDER BY 2 DESC
-- 
Tod McQuillin






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: count different values in column
  2002-04-19 09:30 count different values in column Albrecht Berger <berger1517@gmx.ch>
  2002-04-19 09:40 ` Re: count different values in column Tod McQuillin <devin@spamcop.net>
@ 2002-04-19 09:55   ` Fduch the Pravking <fduch@antar.bryansk.ru>
  0 siblings, 0 replies; 7+ messages in thread

From: Fduch the Pravking @ 2002-04-19 09:55 UTC (permalink / raw)
  To: Tod McQuillin <devin@spamcop.net>; +Cc: Albrecht Berger <berger1517@gmx.ch>; pgsql-sql

On Fri, Apr 19, 2002 at 04:40:35AM -0500, Tod McQuillin wrote:
> On Fri, 19 Apr 2002, Albrecht Berger wrote:
> 
> > Now I want to count the different values in the column.
> >
> > Resulttable :
> >    a
> > ------
> > 10
> > 12
> > 12
> > 12
> > 14
> > 14
> > 15
> >
> > I need the value which is repeated most in the resulttable (in this example
> > 12 ) !
> 
> SELECT a, count(a) FROM resulttable GROUP BY a ORDER BY 2 DESC

Note that count on NULL values will always give you 0:

fduch=> INSERT INTO resulttable VALUES (NULL);
INSERT 1702218 1
(repeat some times)

fduch=> SELECT a, count(a) FROM resulttable GROUP BY a ORDER BY 2 DESC;
 a  | count
----+-------
 12 |     3
 14 |     2
 10 |     1
 15 |     1
    |     0
(5 rows)

-- 
Fduch M. Pravking



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: count different values in column
  2002-04-19 09:30 count different values in column Albrecht Berger <berger1517@gmx.ch>
@ 2002-04-19 10:00 ` Gautham S. Rao <gautam.rao@tatainfotech.com>
  2 siblings, 0 replies; 7+ messages in thread

From: Gautham S. Rao @ 2002-04-19 10:00 UTC (permalink / raw)
  To: Albrecht Berger <berger1517@gmx.ch>; pgsql-sql

Hi Berger,

Try,
select a from  Resulttable group by a having count(a) = (select max(cnt)
from (select count(a) as cnt from  Resulttable group by a) as tmp);

Regards,
Gautham.

----- Original Message -----
From: "Albrecht Berger" <berger1517@gmx.ch>
To: "pgsql" <pgsql-sql@postgresql.org>
Sent: Friday, April 19, 2002 3:00 PM
Subject: [SQL] count different values in column


> Hello,
> today I have a new question :)
>
> I've a resulttable is generated by a couple of subselects and joins which
> contains only one column.
>
> Now I want to count the different values in the column.
>
> Resulttable :
>    a
> ------
> 10
> 12
> 12
> 12
> 14
> 14
> 15
>
> I need the value which is repeated most in the resulttable (in this
example
> 12 ) !
>
>
> Any suggestions ?
>
>
> Thx
> berger
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2002-04-20 17:23 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-19 09:27 count different values in column? Thorsten Wenzlaff <thorsten.wenzlaff@gmx.de>
2002-04-20 17:23 ` Re: count different values in column? Rajesh Kumar Mallah <mallah@trade-india.com>
2002-04-19 09:30 count different values in column Albrecht Berger <berger1517@gmx.ch>
1970-01-01 00:00 ` Christoph Haller <ch@rodos.fzk.de>
2002-04-19 09:40 ` Tod McQuillin <devin@spamcop.net>
2002-04-19 09:55   ` Fduch the Pravking <fduch@antar.bryansk.ru>
2002-04-19 10:00 ` Gautham S. Rao <gautam.rao@tatainfotech.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox