Re: RE: counting distinct rows on more than one column

Поиск
Список
Период
Сортировка
От Jim Ballard
Тема Re: RE: counting distinct rows on more than one column
Дата
Msg-id 01b001c0b7d6$3fccbac0$8300a8c0@planet
обсуждение исходный текст
Ответ на RE: counting distinct rows on more than one column  (Jeff Eckermann <jeckermann@verio.net>)
Список pgsql-sql
If the fields are fixed length character type, then the simpler
concatenation should work.

Actually, the requirement is only that all but the final field be fixed
length.

And if they aren't fixed length, you can cast them to be such, as long as
you know the maximum length of the string values, as in the following where
that maximum is 20 and we are looking at 3 fields:

select count(distinct (cast(field1 as char(20)) || cast(field2 as char(20))
|| field3)) from ...

Jim Ballard

----- Original Message -----
From: "Jeff Eckermann" <jeckermann@verio.net>
To: "'Dirk Lutzebaeck'" <lutzeb@aeccom.com>; "Michael Fork"
<mfork@toledolink.com>
Cc: <pgsql-sql@postgresql.org>
Sent: Wednesday, March 28, 2001 3:43 PM
Subject: [SQL] RE: counting distinct rows on more than one column


> I don't think this will necessarily work:
>
> field1 | field2
> aa     |  ab
> a       |  aab
>
> These are two distinct rows, so should be counted as two.
> The proposed method would count them as one.
> You can get around this problem by doing:
> count (distinct (a || x || b))
> where x is some character not found in your data.
>
> > -----Original Message-----
> > From: Dirk Lutzebaeck [SMTP:lutzeb@aeccom.com]
> > Sent: Wednesday, March 28, 2001 1:32 PM
> > To: Michael Fork
> > Cc: pgsql-sql@postgresql.org
> > Subject: Re: counting distinct rows on more than one column
> >
> > Michael Fork writes:
> >  > In 7.0.3, I believe the following would work:
> >  >
> >  > SELECT count(distinct(a || b)) FROM t;
> >
> > Great, this works! I don't quite get it why...
> >
> > Dirk
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>



В списке pgsql-sql по дате отправления:

Предыдущее
От: Jeff Eckermann
Дата:
Сообщение: RE: counting distinct rows on more than one column
Следующее
От: "Marcos Minshew"
Дата:
Сообщение: SELECT ... FOR UPDATE