Re: [SQL] DISTINCT count(*), possible?

Поиск
Список
Период
Сортировка
От Rudy Gireyev
Тема Re: [SQL] DISTINCT count(*), possible?
Дата
Msg-id 199906162007.QAA05181@hub.org
обсуждение исходный текст
Ответ на Re: [SQL] DISTINCT count(*), possible?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [SQL] DISTINCT count(*), possible?
Список pgsql-sql
Out of curiosity, more than anything else.
Would the group by solve this problem?

Rudy

On 16 Jun 99, at 10:24, Tom Lane wrote:

> Another way is
> 
>  SELECT DISTINCT field INTO temp_table FROM mytable;
>  SELECT count(*) FROM temp_table;
>  DROP TABLE temp_table;
> 
> which is arguably more efficient than the previous solution
> for large tables --- it should involve O(n log n) work rather
> than O(n^2).  For a small table, the overhead of creating and
> dropping a table might overshadow the actual work, though.
> 
> In 6.5 you can use "INTO TEMP temp_table" and avoid worrying
> about having to invent distinct temp table names for concurrent
> users of the database.
> 
> The SQL-standard "SELECT count(DISTINCT field)" would be even nicer,
> of course, but I dunno when someone will get around to it...
> 
>    regards, tom lane
> 
> 




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

Предыдущее
От: Hector M Banda
Дата:
Сообщение: Little Help is needed.
Следующее
От: "Jackson, DeJuan"
Дата:
Сообщение: RE: [SQL] Little Help is needed.