TOKEN "stats_page" READ TOKEN "axis" READ NODE _top_pages_0 SQL > % select case when post_uuid = 'undefined' then '' else post_uuid end as post_uuid, pathname, uniqExact(session_id) as visits from _mv_hits h inner join filtered_sessions_v2 fs on fs.session_id = h.session_id where site_uuid = {{String(site_uuid, 'mock_site_uuid', description="Tenant ID", required=True)}} {% if defined(member_status) %} and member_status IN ( select arrayJoin( {{ Array(member_status, "'undefined', 'free', 'paid'", description="Member status to filter on", required=False) }} || if('paid' IN {{ Array(member_status) }}, ['comped'], []) ) ) {% end %} {% if defined(location) %} and location = {{ String(location, description="Location to filter on", required=False) }} {% end %} {% if defined(pathname) %} and pathname = {{ String(pathname, description="Pathname to filter on", required=False) }} {% end %} {% if defined(post_uuid) %} and post_uuid = {{ String(post_uuid, description="Post UUID to filter on", required=False) }} {% end %} {% if defined(post_type) %} {% if post_type == 'post' %} and post_type = 'post' {% else %} and (post_type != 'post' or post_type is null) {% end %} {% end %} group by post_uuid, pathname order by visits desc limit {{ Int32(skip, 0) }},{{ Int32(limit, 50) }} TYPE ENDPOINT