Skip to content

Instantly share code, notes, and snippets.

@Mr--John-Doe
Last active February 12, 2022 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mr--John-Doe/121d7b8df87c28138af6c3a0e22ef653 to your computer and use it in GitHub Desktop.
Save Mr--John-Doe/121d7b8df87c28138af6c3a0e22ef653 to your computer and use it in GitHub Desktop.
Tuning - slow query
SELECT DISTINCT username
, account_id
, FIRST_VALUE(session_id) OVER (PARTITION BY account_id ORDER BY login_ts) AS session_id
, FIRST_VALUE(ip_address) OVER (PARTITION BY account_id ORDER BY login_ts) AS ip_address
, FIRST_VALUE(country_id) OVER (PARTITION BY account_id ORDER BY login_ts) AS country_id
, FIRST_VALUE(website_entry_point) OVER (PARTITION BY account_id ORDER BY login_ts) AS website_entry_point
, FIRST_VALUE(payment_platform) OVER (PARTITION BY account_id ORDER BY login_ts) AS payment_platform
, FIRST_VALUE(platform_type) OVER (PARTITION BY account_id ORDER BY login_ts) AS platform_type
, FIRST_VALUE(session_duration_s) OVER (PARTITION BY account_id ORDER BY login_ts) AS session_duration_s
, FIRST_VALUE(number_sold_items) OVER (PARTITION BY account_id ORDER BY login_ts) AS number_sold_items
, FIRST_VALUE(sales_gbp) OVER (PARTITION BY account_id ORDER BY login_ts) AS sales_gbp
FROM SALES.SALES_SESSION_AGGREGATION
WHERE is_meaningful_visit = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment