Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.49 KB | None | 0 0
  1. SELECT
  2.   uniqExact(year, month, day)
  3. FROM
  4.   (
  5.     SELECT
  6.       any(currency) as currency,
  7.       any(dict_currency_rate) as dict_currency_rate,
  8.       sumIf(payouts, status = 'confirmed') as confirmed_payouts,
  9.       sumIf(payouts, status = 'pending') as pending_payouts,
  10.       sumIf(payouts, status = 'declined') as declined_payouts,
  11.       sumIf(payouts, status = 'not_found') as not_found_payouts,
  12.       sumIf(payouts, status = 'hold') as hold_payouts,
  13.       sumIf(payouts, status = 'pending_cap') as pending_cap_payouts,
  14.       sum(payouts) as total_payouts,
  15.       toUInt64(0) as hosts,
  16.       toUInt64(0) as clicks,
  17.       toYear(time_slot) as year,
  18.       toMonth(time_slot) as month,
  19.       toDayOfMonth(time_slot) as day
  20.     FROM
  21.       (
  22.         SELECT
  23.           conversion_id,
  24.           any(offer_id) as _offer_id,
  25.           timeSlot(any(created_at)) as time_slot,
  26.           argMax(status, updated_at) as status,
  27.           argMax(currency, updated_at) as currency,
  28.           dictGetFloat64('currencies', 'rate', tuple(toString(currency))) AS dict_currency_rate,
  29.           argMax(currency_rate, updated_at) as currency_rate,
  30.           argMax(income, updated_at) / toFloat64(1) as income,
  31.           argMax(earnings, updated_at) / toFloat64(1) as earnings,
  32.           argMax(payouts, updated_at) / toFloat64(1) as payouts,
  33.           argMax(price, updated_at) / toFloat64(1) as price,
  34.           any(country) as _country,
  35.           any(city_id) as _city_id,
  36.           any(os) as _os,
  37.           any(os_version) as _os_version,
  38.           any(device) as _device,
  39.           any(device_model) as _device_model,
  40.           any(browser) as _browser,
  41.           any(goal) as _goal,
  42.           any(sub1) as _sub1,
  43.           any(sub2) as _sub2,
  44.           any(sub3) as _sub3,
  45.           any(sub4) as _sub4,
  46.           any(sub5) as _sub5,
  47.           any(sub6) as _sub6,
  48.           any(sub7) as _sub7,
  49.           any(sub8) as _sub8,
  50.           any(advertiser_id) as _advertiser_id,
  51.           any(affiliate_id) as _affiliate_id,
  52.           any(advertiser_manager_id) as _advertiser_manager_id,
  53.           any(affiliate_manager_id) as _affiliate_manager_id,
  54.           any(smart_id) as _smart_id
  55.         FROM
  56.           conversions
  57.         WHERE
  58.           client_id = 9999
  59.           AND date >= toDate(1515974400)
  60.           AND created_at >= toDateTime(1515974400)
  61.           AND date <= toDate(1516147200 + 86400)
  62.          AND created_at < toDateTime(1516147200 + 86400)
  63.        GROUP BY
  64.          conversion_id
  65.        HAVING
  66.          status IN ('confirmed')
  67.          AND currency IN ('EUR')
  68.      )
  69.    GROUP BY
  70.      year,
  71.      month,
  72.      day
  73.    UNION ALL
  74.    SELECT
  75.      toFixedString('', 3) as currency,
  76.      toFloat64(1) as dict_currency_rate,
  77.      toFloat64(0) as confirmed_payouts,
  78.      toFloat64(0) as pending_payouts,
  79.      toFloat64(0) as declined_payouts,
  80.      toFloat64(0) as not_found_payouts,
  81.      toFloat64(0) as hold_payouts,
  82.      toFloat64(0) as pending_cap_payouts,
  83.      toFloat64(0) as total_payouts,
  84.      sumMerge(uniq) as hosts,
  85.      countMerge(raw) as clicks,
  86.      toYear(time_slot) as year,
  87.      toMonth(time_slot) as month,
  88.      toDayOfMonth(time_slot) as day
  89.    FROM
  90.      clicks_slice_8
  91.    WHERE
  92.      client_id = 9999
  93.      AND date >= toDate(1515974400)
  94.       AND time_slot >= toDateTime(1515974400)
  95.       AND date <= toDate(1516147200 + 86400)
  96.      AND time_slot < toDateTime(1516147200 + 86400)
  97.    GROUP BY
  98.      year,
  99.      month,
  100.      day
  101.  )
  102. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement