0

在以下 PostgreSQL 8.4.13 表中

author用户给id用户打分):

# \d pref_rep;
                                       Table "public.pref_rep"
  Column   |            Type             |                         Modifiers
-----------+-----------------------------+-----------------------------------------------------------
 id        | character varying(32)       | not null
 author    | character varying(32)       | not null
 good      | boolean                     |
 fair      | boolean                     |
 nice      | boolean                     |
 about     | character varying(256)      |
 stamp     | timestamp without time zone | default now()
 author_ip | inet                        |
 rep_id    | integer                     | not null default nextval('pref_rep_rep_id_seq'::regclass)
Indexes:
    "pref_rep_pkey" PRIMARY KEY, btree (id, author)
Check constraints:
    "pref_rep_check" CHECK (id::text <> author::text)
Foreign-key constraints:
    "pref_rep_author_fkey" FOREIGN KEY (author) REFERENCES pref_users(id) ON DELETE CASCADE
    "pref_rep_id_fkey" FOREIGN KEY (id) REFERENCES pref_users(id) ON DELETE CASCADE

如何找到具有相同id和相同的伪造条目author_ip

即,一些用户注册了多个帐户,然后为其他用户提交了不良记录(上面的goodfairnice列)。但我仍然可以通过他们的author_ip地址来识别他们。

我试图通过获取来找到它们:

# select id, author_ip from pref_rep group by id, author_ip;
           id            |    author_ip
-------------------------+-----------------
 OK490496816466          | 94.230.231.106
 OK360565502458          | 78.106.102.16
 DE25213                 | 178.216.72.185
 OK331482634936          | 95.158.209.5
 VK25785834              | 77.109.20.182
 OK206383671767          | 80.179.90.103
 OK505822972559          | 46.158.46.126
 OK237791033602          | 178.76.216.77
 VK90402803              | 109.68.173.37
 MR16281819401420759860  | 109.252.139.198
 MR5586967138985630915   | 2.93.14.248
 OK341086615664          | 93.77.75.142
 OK446200841566          | 95.59.127.194

但我需要对上述结果进行排序。

请问如何按对数(id,author_ip)desc对其进行排序?

4

1 回答 1

1
select id, pr.author_ip
from
    pref_rep pr
    inner join
    (
        select author_ip
        from pref_rep
        group by author_ip
        having count(*) > 1
    ) s using(author_ip)
order by 2, 1
于 2013-05-01T19:16:11.633 回答