COUNT and SUM at the same time after removing duplicate rows I'm using PostgreSQL and I can't figure out a query for doing a COUNT and a SUM of two different columns. Basically I'm looking for something like a SUM(hits DISTINCT record_id)

The table:

status      record_id      hits     
     0            123         1
     0            123         1
     0            124         1
     0            125         1
     0            126         0
     1            123         0
     1            124         0
     1            125         1
     1            125         1


The desired result:

status   unique_records_count  hits_sum
     0                      4         3
     1                      3         1


Doing a 

SELECT status, COUNT(DISTINCT record_id), SUM(hits)
FROM table
GROUP BY status


returns

status   unique_records_count  hits_sum
     0                      4         4
     1                      3         2
Select A.status,count (A.record_id),sum(A.hits)
from 
(Select distinct status,record_id,hits from YourTable) A
group by A.status