use hahn;
--запрос про оценку интерфейса рекламодателями/специалистами по работе с рекламой
$week=($date)-> { 
RETURN DateTime::Format("%Y-%m-%d")(Datetime::MakeDate(DateTime::StartOfWeek(CAST($date as Date))));};
select
event_week,
sum_if(rate, not(`is_from_uc`)) as rate_wo_uc,
sum_if(rate, `is_from_uc` and event_week>'2021-04-28') as rate_uc
FROM (
    SELECT
    event_week,
    is_from_uc,
    avg(rate) as rate
    FROM hahn.`home/operanalytics/regular/savakian/feedback/maintab`
    WHERE tier IN ('SB', 'SMB CENTER', 'SMB REGIONS') and event_week>='2021-03-08'
GROUP BY $week(log_date) as event_week, if(`is_from_uc`='Со страниц Мастера', true, false) as is_from_uc
)
GROUP BY event_week
ORDER BY event_week ASC;