Обсуждение: finding duplicate numbers in a select distinct statement

Поиск
Список
Период
Сортировка

finding duplicate numbers in a select distinct statement

От
Terry
Дата:
Hello all,

I am trying to do the following query but I would like to know how
many rows were deduplicated in the process:

psql -d foo -c 'SELECT DISTINCT ON (error) error,ev_text FROM
clients_event_log' -o fullfoo


For example, I would want the output to be the following where count
is the number of error rows that were deduplicated.

count    |   error    |   ev_text
55         |  525152 |   Some text
72         |  125124 |   Some other text

I imagine it's using the count function somewhere, just not sure how
to embed that.

Re: finding duplicate numbers in a select distinct statement

От
Grzegorz Jaśkiewicz
Дата:
select count(*) AS count, error, ev_text FROM clients_event_log GROUP BY error, ev_text;

you can add 'HAVING count(*) > X'; , if you want to see only those with count above X, etc.


--
GJ

Re: finding duplicate numbers in a select distinct statement

От
Terry
Дата:
2010/3/3 Grzegorz Jaśkiewicz <gryzman@gmail.com>:
> select count(*) AS count, error, ev_text FROM clients_event_log GROUP BY
> error, ev_text;
>
> you can add 'HAVING count(*) > X'; , if you want to see only those with
> count above X, etc.
>
>
> --
> GJ
>

I was just about to reply to the group.  Would this work too?
psql -d foo -c 'SELECT COUNT(DISTINCT(error)) AS count,error,ev_text
FROM dsclient_logs WHERE ev_id > 23572151 GROUP BY error,ev_text'

Re: finding duplicate numbers in a select distinct statement

От
Grzegorz Jaśkiewicz
Дата:
just try if it does what you want it to do ;)

Re: finding duplicate numbers in a select distinct statement

От
Terry
Дата:
2010/3/3 Terry <td3201@gmail.com>:
> 2010/3/3 Grzegorz Jaśkiewicz <gryzman@gmail.com>:
>> select count(*) AS count, error, ev_text FROM clients_event_log GROUP BY
>> error, ev_text;
>>
>> you can add 'HAVING count(*) > X'; , if you want to see only those with
>> count above X, etc.
>>
>>
>> --
>> GJ
>>
>
> I was just about to reply to the group.  Would this work too?
> psql -d foo -c 'SELECT COUNT(DISTINCT(error)) AS count,error,ev_text
> FROM dsclient_logs WHERE ev_id > 23572151 GROUP BY error,ev_text'
>

My statement was broke.  GJ's was spot on.  Thanks!