Hi guys,
The below query works just fine when used as a “question” see here, but when I create a pulse with it, it never loads see here
Anything I can do to solve this?
Thanks!
SELECT
tot.score_range as minutes_range,
ROUND (
tot.number_of_ocurrences/
(SELECT count(*)
FROM contents c
LEFT JOIN users u on u.id=c.user_id
WHERE u.id IN (
SELECT id
FROM users
WHERE u.type = 'Creator' AND (u.blocked = 'f' OR u.blocked is NULL)
)
AND c.deleted='f' AND c."id" NOT IN (4817))::NUMERIC*100.0,2) percentage_from_total
FROM(
SELECT t.range as score_range, count(*) as number_of_ocurrences
FROM(
SELECT d.id,
(case when d.data >= 0 and d.data< 60 then '0-1'
when d.data >= 60 and d.data< 120 then '1-2'
when d.data >= 120 and d.data< 180 then '2-3'
when d.data >= 180 and d.data< 240 then '3-4'
when d.data >= 240 and d.data< 300 then '4-5'
when d.data >= 300 and d.data< 360 then '5-6'
when d.data >= 360 and d.data< 420 then '6-7'
when d.data >= 420 and d.data< 480 then '7-8'
when d.data >= 480 and d.data< 540 then '8-9'
else ' 9-500'
end) as range
FROM (SELECT
c.id,
(c.data->'duration')::int as data
FROM contents c
LEFT JOIN users u on u.id=c.user_id
WHERE u.id IN (
SELECT id
FROM users
WHERE u.type = 'Creator' AND (u.blocked = 'f' OR u.blocked is NULL)
)
AND c.deleted='f' AND c."id" NOT IN (4817)
) d
) as t
GROUP BY t.range
ORDER BY score_range
) as tot