--select count(*)
--from (
select ds."name" Сценарий
,fb."period" Период
,vdbi.level1_name СтатьяБюджетовГруппа
,dbi."name" СтатьяБюджетов
,dbi.code СтатьяБюджетовКод
,dd."name" МВЗ
,dd.channel_name КаналПродаж
,dp."name" Проект
,dc."name" Валюта
,dpi."name" СтатьяДиР
,sum(fb.amount_cur) СуммаВалюта
,sum(fb.amount_mng) СуммаУпр
,sum(fb.amount_scn) СуммаСценарий
,sum(fb.amount_reg) СуммаРегл
from dm_pf_analysis.fact_budget fb
left join dm_pf_analysis.dim_scenario ds on fb.scenario_id=ds.scenario_id
left join dm_pf_analysis.dim_budget_item dbi on fb.budget_item_id = dbi.budget_item_id
left join dm_pf_analysis.dim_department dd on fb.department_mvz_id = dd.department_id
left join dm_pf_analysis.dim_project dp on fb.project_id = dp.project_id
left join dm_pf_analysis.dim_currency dc on fb.currency_id = dc.currency_id
left join dm_pf_analysis.dim_plcf_item dpi on fb.plcf_item_id = dpi.plcf_item_id
left join dm_pf_analysis.v_dim_budget_item vdbi on fb.budget_item_id = vdbi.budget_item_id
where period between date '2023-07-01' and date '2023-07-31'
and ds."name"='Фактические данные'
and vdbi.level1_name='БДР'
group by
ds."name"
,fb."period"
,vdbi.level1_name
,dbi."name"
,dbi.code
,dd."name"
,dd.channel_name
,dp."name"
,dc."name"
,dpi."name"
--limit 10
-- as test
;
Выдает ошибку:
SQL Error [42803]: ERROR: column "ds.name" must appear in the GROUP BY clause or be used in an aggregate function