finding duplicate numbers in a select distinct statement

Started by Terryabout 16 years ago5 messagesgeneral
Jump to latest
#1Terry
td3201@gmail.com

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.

#2Grzegorz Jaśkiewicz
gryzman@gmail.com
In reply to: Terry (#1)
Re: finding duplicate numbers in a select distinct statement

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

#3Terry
td3201@gmail.com
In reply to: Grzegorz Jaśkiewicz (#2)
Re: finding duplicate numbers in a select distinct statement

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'

#4Grzegorz Jaśkiewicz
gryzman@gmail.com
In reply to: Terry (#3)
Re: finding duplicate numbers in a select distinct statement

just try if it does what you want it to do ;)

#5Terry
td3201@gmail.com
In reply to: Terry (#3)
Re: finding duplicate numbers in a select distinct statement

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!