How to get total unique users as well as grouping by category
<p>I have the following SQL table:</p>

<pre><code>user_id | device | num_uses
---------------------------
1       | phone  | 10
1       | tv     | 5
2       | phone  | 15
3       | tv     | 45
</code></pre>

<p>I want to come up with a query which will return the number of users per device, but also the total number of unique users.</p>

<p>Is it possible to do this with one query, or is my only option to create 2 queries, one for the number of users per device, then another to get the distinct number of users?</p>

<p>The query I have to get the number of users by device is:</p>

<pre><code>select count(user_id), device from usage group by device;
</code></pre>

<p>which gives me:</p>

<pre><code>count  | device
---------------
2      | phone
2      | tv
</code></pre>

<p>Expected result would be:</p>

<pre><code>category_count | device   | total_distinct_users
------------------------------------------------
2              | phone    |  3
2              | tv       |  3
</code></pre>