SELECT
  userid,
  SUM(CASE WHEN typeid=1 THEN 1 ELSE 0 END)/COUNT(*) AS percent
FROM
  uses
GROUP BY
  userid



Cory Nelson wrote:
Hey guys, I'm hoping to get some help with this:

create table uses(userid integer, typeid integer);
insert into uses values(1, 1);
insert into uses values(1, 1);
insert into uses values(2, 1);
insert into uses values(2, 2);

now i'm trying to build a select that gives the result:
userid | percent
1            1.0
2            0.5

Where percent is the percent of typeids for that userid where typeid=1.

I've been trying to do this unsuccessfully for a couple days, so any
help would be greatly appreciated.


Reply via email to