I have table1 with 2 ID's and 2 values per ID (Y,N). I can count the values by the following query:
select id ,count(*) as "total" ,choice from table1 where id in (1,8) group by id, choice I get the following results:
| id | total | choice |
|---|---|---|
| 1 | 55 | N |
| 1 | 17 | Y |
| 8 | 319 | N |
| 8 | 123 | Y |
Is there a way to write a query that will give me the percentages of each value (Y,N) for each id?
(id1: 55/55+17 (N), 17/55+17 (Y), etc.)
Desired result:
| id | total | choice | percent |
|---|---|---|---|
| 1 | 55 | N | 0.236 |
| 1 | 17 | Y | 0.764 |
| 8 | 319 | N | 0.7222 |
| 8 | 123 | Y | 0.278 |
Would I still need to use count(*) in the query?