How many users have signed up for an institution?

Query

select count(distinct r.user_id)
from rdc_accounts as r
inner join users as u
on r.user_id = u.user_id
where u.primary_institution_id = 'a35d1430-a580-11e3-a5e2-0800200c9a66'
group by r.user_id
;

Example Output

  count
-------
     1
     1
     1
     1
     1
     1
(6 rows)

How many RDC accounts have we approved in the past few days?

Query

select date_trunc('day', date_changed), count(*)
from rdc_account_status_changes as r
inner join users as u
on r.user_id = u.user_id
where status_to = 2
and u.primary_institution_id <> '5e4dcedb-567f-417b-b428-2231d4713b63'
and date_changed > now() - interval '1d'
group by date_trunc('day', date_changed)
order by date_trunc('day', date_changed) desc
;

Example Output

        date_trunc       | count
------------------------+-------
 2015-06-22 00:00:00-05 |     1
(1 row)