fix: align clickhouse with prisma query

This commit is contained in:
Bas Broekhuizen 2025-09-04 15:46:29 +02:00
parent b8b773a402
commit c924ef8582

View file

@ -62,30 +62,30 @@ async function clickhouseQuery(
sql = `
select
sumIf(1, event_type = 1) as "pageviews",
uniq(session_id) as "visitors",
uniq(visit_id) as "visits",
uniq(country) as "countries",
sum(length(event_name)) as "events"
uniqIf(session_id, event_type = 1) as "visitors",
uniqIf(visit_id, event_type = 1) as "visits",
uniqIf(country, event_type = 1) as "countries",
sumIf(1, event_type = 2) as "events"
from website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
${filterQuery}
`;
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
${filterQuery}
`;
} else {
sql = `
select
sum(views) as "pageviews",
uniq(session_id) as "visitors",
uniq(visit_id) as "visits",
uniq(country) as "countries",
sum(length(event_name)) as "events"
sumIf(views, event_type = 1) as "pageviews",
uniqIf(session_id, event_type = 1) as "visitors",
uniqIf(visit_id, event_type = 1) as "visits",
uniqIf(country, event_type = 1) as "countries",
sumIf(1, event_type = 2) as "events"
from website_event_stats_hourly website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
${filterQuery}
`;
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
${filterQuery}
`;
}
return rawQuery(sql, params);