Как создать функцию фильтр PostgreSQL до MySQL?
Я пытался сделать следующее, но не смог:
select
CASE WHEN statusstorie = false and statusTwentyFive = true and category not in ('goals') and space = 'personal' THEN count(*) ELSE 0 END as "25%",
CASE WHEN statusstorie = false and statusFifty = true and category not in ('goals') and space = 'personal' THEN count(*) ELSE 0 END as "50%",
CASE WHEN statusstorie = false and statusSeventyFive = true and category not in ('goals') and space = 'personal' THEN count(*) ELSE 0 END as "75%",
CASE WHEN statusstorie = false and statusOneHundred = true and category not in ('goals') and space = 'personal' THEN count(*) ELSE 0 END as "100%"
from goals
PSQL Пример:
select
count(*) filter(where statusstorie = false and statusTwentyFive = true and category not in ('goals') and space = 'personal') "25%",
count(*) filter(where statusstorie = false and statusFifty = true and category not in ('goals') and space = 'personal') "50%",
count(*) filter(where statusstorie = false and statusSeventyFive = true and category not in ('goals') and space = 'personal') "75%",
count(*) filter(where statusstorie = false and statusOneHundred = true and category not in ('goals') and space = 'personal') "100%"
from goals
Примечание: Если возможно, я хотел бы воспроизвести функцию на MySQL
CREATE FUNCTION filter()