clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 756682 fiddles created (13644 in the last week).

CREATE TABLE t (user_uuid text, value int, state bool); insert into t values ('uuid_1', 111, true), ('uuid_1', 111, false), ('uuid_1', 111, false), ('uuid_1', 111, false), ('uuid_2', 333, true), ('uuid_2', 444, true), ('uuid_2', 555, false), ('uuid_3', 666, true), ('uuid_4', 777, false), ('uuid_1', 222, true), ('uuid_1', 222, true);
11 rows affected
 hidden batch(es)


SELECT user_uuid, COUNT(*) cnt, ROUND (100.0 * (SUM(CASE WHEN value = '111' AND state = true THEN 1 ELSE 0 END)) / COUNT(*), 1) AS percent FROM t GROUP BY user_uuid
user_uuid cnt percent
uuid_2 3 0.0
uuid_3 1 0.0
uuid_1 6 16.7
uuid_4 1 0.0
 hidden batch(es)


SELECT user_uuid, COUNT(*) cnt, ROUND (100.0 * (COUNT(*) FILTER (WHERE value = '111' AND state = true)) / COUNT(*), 1) AS percent FROM t GROUP BY user_uuid
user_uuid cnt percent
uuid_2 3 0.0
uuid_3 1 0.0
uuid_1 6 16.7
uuid_4 1 0.0
 hidden batch(es)