-1

ユーザーがコメントできるブログがあるとします。コメントがスパムの場合、人々はそれを削除投票できます。その場合、次のテーブルに行が挿入されます。

SPAM_REPORTS
comment_id - ip

テーブルは で一意comment_id, ipです。

ここで、レポートの最大数で並べ替えられた comment_id を出力したいと考えています。

仮定しSPAM_REPORTSます:

comment_id         ip
     6      888.xxx.xxx.xxx
     5      111.xxx.xxx.xxx
     5      222.xxx.xxx.xxx
     6      444.xxx.xxx.xxx
     1      333.xxx.xxx.xxx
     5      555.xxx.xxx.xxx

出力を次のようにしたい:

comment_id  count
    5        3
    6        2
    1        1
4

1 に答える 1

0

これを試して

 select comment_id , count(*) as count from SPAM_REPORTS
 group by comment_id 
 order by count desc

デモはこちら

于 2013-07-20T13:38:45.707 に答える