Guest User

Untitled

a guest
Apr 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. -- Evan Appel, 2018
  2. -- This query creates a table that can then be fit into a pivot table for analysis
  3. -- regarding day to day sales across sites and routes of purchase.
  4.  
  5. SELECT date AS date,
  6. site AS site,
  7. CASE EXTRACT (dayofweek
  8. FROM date)
  9. WHEN 0 THEN 'SUNDAY'
  10. WHEN 1 THEN 'MONDAY'
  11. WHEN 2 THEN 'TUESDAY'
  12. WHEN 3 THEN 'WEDNESDAY'
  13. WHEN 4 THEN 'THURSDAY'
  14. WHEN 5 THEN 'FRIDAY'
  15. WHEN 6 THEN 'SATURDAY'
  16. END AS day ,
  17. SUM(phone_tx) AS phone_tx ,
  18. SUM(web_tx) AS web_tx ,
  19. SUM(total_tx) AS total_tx
  20. FROM
  21. ( SELECT TRUNC(CONVERT_TIMEZONE('PST',g.transaction_time_utc)) AS date
  22. , w.website_short_name AS site
  23. , CASE
  24. WHEN g.source = 'ADMIN' THEN 1
  25. ELSE 0
  26. END AS phone_tx ,
  27. CASE
  28. WHEN g.source != 'ADMIN' THEN 1
  29. ELSE 0
  30. END AS web_tx ,
  31. 1 AS total_tx
  32. FROM gateway.aggregate_t g
  33. LEFT JOIN reference.websiteidentifiers w
  34. ON g.website_id = w.website_id
  35. WHERE TRUNC(CONVERT_TIMEZONE('PST',g.transaction_time_utc)) BETWEEN CURRENT_DATE - 30 AND CURRENT_DATE
  36. AND (g.billing_email NOT SIMILAR TO '%(test)%'
  37. OR g.billing_email IS NULL)
  38. AND (g.first_name NOT SIMILAR TO '%(test)%'
  39. OR g.first_name IS NULL)
  40. AND (g.last_name NOT SIMILAR TO '%(test)%'
  41. OR g.last_name IS NULL)
  42. AND g.transaction_status NOT SIMILAR TO '%(Error|Declined|Void|Refund|Credit)%'
  43. AND g.transaction_type NOT SIMILAR TO '%(Error|Declined|Void|Refund|Credit)%'
  44. -- AND g.website_id = 5
  45. GROUP BY g.transaction_time_utc ,
  46. g.source, w.website_short_name)
  47. GROUP BY date, site
  48. ORDER BY date DESC
Add Comment
Please, Sign In to add comment