Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.36 KB | None | 0 0
  1. SELECT
  2.    toStartOfMonth(DATE) AS MONTH
  3.    ,uniq(
  4.      toUInt32OrZero(
  5.           multiIf( EXTRACT(request_uri, '/category/[a-z\-]*([0-9]{2,7}).*')<>''
  6.             , EXTRACT(request_uri, '/category/[a-z\-]*([0-9]{2,7}).*')
  7.             , extractURLParameter(request_uri, 'category_id')<>''
  8.             , extractURLParameter(request_uri, 'category_id')
  9.             , extractURLParameter(request_uri, 'categories_id')<>''
  10.             , extractURLParameter(request_uri, 'categories_id')
  11.             , visitParamExtractString(post_params, 'categories_id') <> ''
  12.             , visitParamExtractString(post_params, 'categories_id')
  13.             , ''
  14.  
  15.               )
  16.           ) AS categories_id
  17.       ) AS unq_categories_id
  18.   , uniq(customers_id)  AS unq_customers_id
  19.   , uniq(concat(toString(categories_id),'_', toString(customers_id))) AS cnt_view_categories
  20. , multiIf(
  21.     MATCH(user_agent, 'MamsyApp'), 'MamsyApp'
  22.   , MATCH(user_agent, 'iPhone|iPad|iPod|Android|Windows Phone'), 'Mobile'
  23.   , 'Desktop'
  24.   )            AS platform
  25. FROM site_request AS sr
  26.  
  27. WHERE customers_id != 0
  28.   AND DATE >= '2019-01-01'
  29.   AND categories_id IS NOT NULL
  30.   AND categories_id != 0
  31.   AND date_added >= dictGetDateTime('categories','date_start',toUInt64( categories_id ))
  32.   AND date_added <= dictGetDateTime('categories','date_end',toUInt64( categories_id ))
  33. GROUP BY  MONTH, platform
  34.  
  35. -- having unq_customers_id > 20
  36.  
  37. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement