WITH ewints(data) AS (
VALUES
('{"site": {"id": "1111111", "url": "https://111111", "name": "111111"}, "client": {"id": "111111111", "owner": {"id": "111111111", "unp": "11111111", "name": "ЗАО \"11111\""}, "tariff": null, "client_id": "111111111", "locale_name": "1111111", "default_name": "11111111"}, "scopes": "1111111", "request": {"uri": "https://o111111", "lang": "ru", "port":33333, "user_agent": "1111 (1111)"}, "event_id": null, "alias_ids": ["11111111", "11111111"], "expires_in": 0, "grant_type": "111111", "token_hash": "1111111111", "auth_method": "phone", "session_uuid": "111111111"}'::jsonb),
('{"site": {"id": "1111111", "url": "https://111111", "name": "111111"}, "client": {"id": "111111111", "owner": {"id": "111111111", "unp": "11111111", "name": "ЗАО \"11111\""}, "tariff": null, "client_id": "111111111", "locale_name": "1111111", "default_name": "11111111"}, "scopes": "1111111", "request": {"uri": "https://o111111", "lang": "ru", "port":33333, "user_agent": "1111 (1111)"}, "event_id": null, "alias_ids": ["11111111", "11111111"], "expires_in": 0, "grant_type": "111111", "token_hash": "1111111111", "auth_method": "attribute", "session_uuid": "111111111"}'::jsonb)
)
SELECT SUM(CASE (data->>'auth_method'='phone') WHEN true THEN 1 ELSE 0 END) AS "Authorization_by_phone",
COUNT(*) FILTER (WHERE data->>'auth_method' = 'phone') AS authorization_by_phone_simpler,
COUNT(*) FILTER (WHERE data->>'auth_method' IN ('phone', 'attribute')) AS "like this?"
FROM ewints;
Так? Или что-то другое нужно?