Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- uniqExact(year, month, day)
- FROM
- (
- SELECT
- any(currency) as currency,
- any(dict_currency_rate) as dict_currency_rate,
- sumIf(payouts, status = 'confirmed') as confirmed_payouts,
- sumIf(payouts, status = 'pending') as pending_payouts,
- sumIf(payouts, status = 'declined') as declined_payouts,
- sumIf(payouts, status = 'not_found') as not_found_payouts,
- sumIf(payouts, status = 'hold') as hold_payouts,
- sumIf(payouts, status = 'pending_cap') as pending_cap_payouts,
- sum(payouts) as total_payouts,
- toUInt64(0) as hosts,
- toUInt64(0) as clicks,
- toYear(time_slot) as year,
- toMonth(time_slot) as month,
- toDayOfMonth(time_slot) as day
- FROM
- (
- SELECT
- conversion_id,
- any(offer_id) as _offer_id,
- timeSlot(any(created_at)) as time_slot,
- argMax(status, updated_at) as status,
- argMax(currency, updated_at) as currency,
- dictGetFloat64('currencies', 'rate', tuple(toString(currency))) AS dict_currency_rate,
- argMax(currency_rate, updated_at) as currency_rate,
- argMax(income, updated_at) / toFloat64(1) as income,
- argMax(earnings, updated_at) / toFloat64(1) as earnings,
- argMax(payouts, updated_at) / toFloat64(1) as payouts,
- argMax(price, updated_at) / toFloat64(1) as price,
- any(country) as _country,
- any(city_id) as _city_id,
- any(os) as _os,
- any(os_version) as _os_version,
- any(device) as _device,
- any(device_model) as _device_model,
- any(browser) as _browser,
- any(goal) as _goal,
- any(sub1) as _sub1,
- any(sub2) as _sub2,
- any(sub3) as _sub3,
- any(sub4) as _sub4,
- any(sub5) as _sub5,
- any(sub6) as _sub6,
- any(sub7) as _sub7,
- any(sub8) as _sub8,
- any(advertiser_id) as _advertiser_id,
- any(affiliate_id) as _affiliate_id,
- any(advertiser_manager_id) as _advertiser_manager_id,
- any(affiliate_manager_id) as _affiliate_manager_id,
- any(smart_id) as _smart_id
- FROM
- conversions
- WHERE
- client_id = 9999
- AND date >= toDate(1515974400)
- AND created_at >= toDateTime(1515974400)
- AND date <= toDate(1516147200 + 86400)
- AND created_at < toDateTime(1516147200 + 86400)
- GROUP BY
- conversion_id
- HAVING
- status IN ('confirmed')
- AND currency IN ('EUR')
- )
- GROUP BY
- year,
- month,
- day
- UNION ALL
- SELECT
- toFixedString('', 3) as currency,
- toFloat64(1) as dict_currency_rate,
- toFloat64(0) as confirmed_payouts,
- toFloat64(0) as pending_payouts,
- toFloat64(0) as declined_payouts,
- toFloat64(0) as not_found_payouts,
- toFloat64(0) as hold_payouts,
- toFloat64(0) as pending_cap_payouts,
- toFloat64(0) as total_payouts,
- sumMerge(uniq) as hosts,
- countMerge(raw) as clicks,
- toYear(time_slot) as year,
- toMonth(time_slot) as month,
- toDayOfMonth(time_slot) as day
- FROM
- clicks_slice_8
- WHERE
- client_id = 9999
- AND date >= toDate(1515974400)
- AND time_slot >= toDateTime(1515974400)
- AND date <= toDate(1516147200 + 86400)
- AND time_slot < toDateTime(1516147200 + 86400)
- GROUP BY
- year,
- month,
- day
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement