select event, event_time from events where event_date >= '2020-08-10' and event_date <= '2020-08-18' and event_time > 1597161600 limit 20; The front-end displays 1000 items, and the download can download 1000000 items.
The query range of this table is: user SSID/UUID, event, event properties, event user properties, all_value type of user properties and business object properties.
tip
If the query field is event_params xxxx_item_id, the custom query considers the field to be the report id of the business object (item) named xxx. If there is a real property named xxxx_item_id and you just want to query the value of this event property, you can use the function mapElement ({event property type} _params, 'xxxx_item_id') , where the event property type may be int, string, float, for example, mapElement (string_params, 'xxxx_item_id') .
Tip: event_params.xxx .yyy, user_profiles.xxx, item_profiles.xxx .yyy three fields suggest aliasing, otherwise the query may have problems.
The query range of this table is: user SSID/UUID, all_value/last_value type of user properties.
The query range of this table is: all_value/last_value type of business object related information
The query range of this table is: the user statistics contained in the sub-group caliber id, hash_uid, sub-group id, etc
stat_standard_id
hash_uid
cohort_id
Under the "metadata" tab, you can view all subgroup names, subgroup IDs, and subgroup numbers.
Currently does not support querying the historical version of the cluster, so the current query through the cluster id is the most recent successfully refreshed cluster, consistent with other advanced analysis scenarios.
For event_date and last_active_date, the following functions are currently supported. If you need other functions, you can give feedback to customer service.
Note: Current custom SQL queries do not support SQL queries using dynamic parameters, such as:
select event, event_time from events where event = ‘app_launch’ and event_date = ${event_date} limit 20; --Where event = ${event_name} This dynamic parameter is passed in by subsequent dynamic, SQL queries in the form of such dynamic parameters are currently not supported
Support function:
subtractMonths,subtractWeeks,subtractDays
addMonths, addWeeks, addDays
toStartOfQuarter,toStartOfMonth,toStartOfISOYear,toMonday,toStartOfWeek
Note: The toStartOfWeek function, when the mode is even, starts on Monday, otherwise it is Sunday.
Wrong usage:
select event from events where toMonth(event_date) = 9; select event from events where subtractDays(event_date, 10) = '2021-09-20';
In the above way, the custom query will prompt that the event_date cannot be derived.
Correct usage:
select event from events where event_date >= subtractDays(today(), 10);
In any case, it is strongly recommended to use event_date as the date filter, and for more precise time intervals, use event_date + event_time to limit.
event_date indicates the date of the event, accurate to the day, can be used to speed up the query, the default default is the last 7 days (including today).
Currently only the format "YYYY-MM-dd" is supported, for example: event_date = '2020-08-10'.
event_time represents the time of the event, a 10-digit timestamp, accurate to the second, and can be used to provide a more accurate time interval.
The event_date of the domestic station access application is UTC + 8 (East Eighth District) time, and the event_date of the international station access application is UTC (Zero Time Zone) time.
For example:
event_time = 1597273200, domestic station event_date '2020-08-13'
event_time = 1597273200, international station event_date '2020-08-12'
Domestic station access application: Check the events that occurred from 6:00 on August 10, 2020 to 14:00 on August 12, 2020 Beijing time
select event from events where event_time >= 1597010400 and event_time <= 1597212000 and event_date >= '2020-08-10' and event_date <= '2020-08-12'
The international station accesses the application, and the time zone of the application is UTC time: check the events that occurred from 6:00 UTC on August 10, 2020 to 14:00 UTC on August 12, 2020
select event from events where event_time >= 1597039200 and event_time <= 1597240800 and event_date >= '2020-08-10' and event_date <= '2020-08-12'
The international station accesses the application, and the time zone of the application is UTC + 7 time: Query the events that occurred from 6:00 UTC + 7 time on August 10, 2020 to 14:00 UTC + 7 time on August 12, 2020, which is equivalent to querying the events that occurred from 23:00 UTC time on August 9, 2020 to 7:00 UTC time on August 12, 2020:
select event from events where event_time >= 1597014000 and event_time <= 1597215600 and event_date >= '2020-08-09' and event_date <= '2020-08-12'
Note : Whenever possible, it is recommended that you specify a start and stop time for event_date in SQL to speed up queries. If you don't add it, the SQL custom query feature automatically assembles time limits, which may produce data that is different from the time period you expected.
When joining with the events table, last_active_date can be automatically derived from event_date, otherwise it is recommended that the user specify last_active_date range.
Semantic example:
select user_profiles.gender from users where last_active_date >= '2020-08-10'
select gender, hash_uid, user_id from events as table_a left join ( select hash_uid, user_profiles.gender as gender from users where user_profiles.gender is not null ) as table_b on table_a.hash_uid == table_b.hash_uid where event_date <= '2020-08-10' and event = 'A' limit 500;
The SQL does not specify a start event_date for the event, so the default start event_date is 365 days ago today, assumed to be '2019-10-11'. At this point, in the join clause, the default query last_active_date > = '2019-10-11' users.
It is worth noting that the typical misspelling of this case is:
select gender, hash_uid, user_id from events as table_a left join ( select hash_uid, user_profiles.gender as gender from users where user_profiles.gender is not null where last_active_date <= '2020-08-10' ) as table_b on table_a.hash_uid == table_b.hash_uid where event_date <= '2020-08-10' limit 500;
If a user enters last_active_date < = '2020-08-10', the semantics of the join clause becomes - querying for users who had no events after August 10, 2020, rather than querying for users who had events before August 10, 2020.
quantile(level)(expr)
parameter
Median (expr) is equivalent to quantile (0.5) (expr)
Note: This function uses Reservoir_sampling stochastic algorithm, so the results are approximate and non-deterministic.
For example, in the order event of August 10, 2020, the percentiles are 0.2.
select quantile(0.2)(event_params.order.money) from events where event = 'order' and event_date = '2020-08-10' limit 1;
Calculate sigma ((x - x) ^ 2)/(n - 1) , where n is the sample size and x is the average of x .
Example: Query the variance of the amount in the order event on August 10, 2020
select varSamp(event_params.order.money) from events where event = 'order' and event_date = '2020-08-10' limit 1;
Grammar:
SELECT if(cond, then, else)
If the condition cond evaluates to a non-zero value, the result of the expression then is returned, and the result of the expression else, if present, is skipped. If cond is zero or NULL, the result of the then expression is skipped and the result of the else expression, if present, is returned. 、
Parameter:
Example: Query the person who triggered event A more than event B between October 6 and 12, 2020.
select distinct user_unique_id
from (select user_unique_id as user_unique_id,
if(event = 'A', count(1), 0) as event1_cnt,
if(event = 'B', count(1), 0) as event2_cnt
from events
where event in ('A', 'B')
and event_date >= '2020-10-06'
and event_date <= '2020-10-12'
group by user_unique_id, event
limit 1000)
group by user_unique_id
having sum(event1_cnt) > sum(event2_cnt)
Returns an array of the same size as the source array, where each element represents the number of times the original array element corresponding to its subscript appears in the original array. Common usage is similar to the windowing function in hive row_number ()
Parameter:
Example: Query the previous three times of different events from October 25 to November 1, 2020
select *
from (
select event, time_arr, row_number
from (
select event,
groupArray(time) as time_arr,
arrayEnumerate(time_arr) as row_number
from (select distinct event, event_time as time
from events
where event_date >= '2020-10-25'
and event_date <= '2020-11-01'
order by time) a
group by event
)
array join
time_arr
, row_number
)
where row_number <= 3;
Result set:
event | time_arr | row_number |
|---|---|---|
wechat_unsubscribe | 1603967567 | 1 |
wechat_unsubscribe | 1603968269 | 2 |
wechat_unsubscribe | 1603968275 | 3 |
goods_detail_view | 1603469824 | 1 |
goods_detail_view | 1603473124 | 2 |
goods_detail_view | 1603479424 | 3 |
Supplement:
This usage is similar to row_number () for HQL, which is written as:
select *
from
(
select event,
row_number() over(partition by event order by event_time) as row_number
from events
) a
where a.row_number <= 3;
Similar functions:
arrayEnumerateUniq、arrayEnumerateDense
match(haystack, pattern)
Example:
select distinct user_profiles.user_id, multiMatchAny(user_profiles.user_id, ['^[0-9]*$', '^\d{10}$']) as is_match from events where event_date > '2021-03-01' limit 20;
Result set:
user_profiles.user_id | is_match |
|---|---|
209041 | 1 |
unknown | 0 |
multiMatchAny(haystack, [pattern1, pattern2, ...])
multiMatchAnyIndex(haystack, [pattern1, pattern2, ...])
Example:
select distinct user_profiles.user_id, multiMatchAnyIndex(user_profiles.user_id, ['^[0-9]*$', '^([a-zA-Z0-9_-]\.)+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$', '(\.[a-zA-Z0-9_-]@)+']) as regex_index from events where event_date > '2021-03-01' limit 2;
Result set:
user_profiles.user_id | regex_index |
|---|---|
209041 | 1 |
xxxx.xxx@xxx.com | 3 |
aaa@aaa.com | 2 |
unknown | 0 |
select event from events where user_profiles.user_id = 'datafinder@datarangers.com' and event_date = '2020-08-10' limit 20
select count(event) from events where event = 'event_name' and event_time > 1596988800 and event_time < 1597161600 limit 20
select count(distinct hash_uid) from events where (event = 'event_1' or event = 'event_2' and event != 'event_3') and event_time > 1596988800 and event_time < 1597161600 limit 20
select user_profiles.user_id, event_params.{event_name}.{event_param_name} from events where event = 'sogo' and event_date > '2020-01-01' order by event_time desc limit 10;
select case when amount > 10 then 'x>10' when amount >5 and amount <= 10 then '5<x<=10' else 'x<=5' end from ( select event_params.buy.amount as amount from events where event = '`buy`' and event_date > '2020-06-01' and event_date < '2020-08-02' limit 200 )
select event from events where hash_uid in (select hash_uid from cohorts where cohort_id = 154) and event_date = yesterday()
select user_id from users where hash_uid in (select hash_uid from cohorts where cohort_id = 154) and last_active_date >= '2021-01-01'
Refactor the query using the WITH clause WITH filtered_valid_users AS ( -- Sub-query: filter out user_id non-empty user base information SELECT hash_uid, user_id FROM users WHERE user_id IS NOT NULL ) Main query: associated transaction table and filtered user table, filtered by date SELECT `event_params.predefine_pageview_hide.duration` AS pageview_hide_duration, Alias fields for easy identification `event_params.duration` AS event_duration, event_time, table_a.hash_uid, filtered_valid_users.user_id FROM events AS table_a INNER JOIN filtered_valid_users ON table_a.hash_uid = filtered_valid_users.hash_uid SQL standard equality operator WHERE event_date BETWEEN '2026-03-13' AND '2026-03-15' -- Simplified date range judgment LIMIT 500;
tip
"Custom Query" currently only supports the following functions. If you need other functions, please contact customer service.
Function type | Supported functions |
|---|---|
aggregate function | 'avg', 'count', 'min', 'max', 'sum', 'varSamp', 'quantile', 'median', 'groupArray','any' |
conditional function | 'if', 'multiIf' |
Other functions | 'isNaN', 'isFinite', 'least', 'isInfinite', 'greatest','toTypeName','neighbor', |
Nullable handler | 'coalesce', 'nullIf', 'ifNull', 'isNull', 'assumeNotNull', 'toNullable', 'isNotNull' |
array function | 'indexOf', 'emptyArrayUInt16', 'arrayEnumerate', 'emptyArrayFloat32', 'arrayDifference', 'empty', 'emptyArrayDate', 'notEmpty', 'has', 'arrayResize', 'emptyArrayString', 'emptyArrayInt64', 'arraySlice', 'arrayElement', 'arrayUniq', 'arrayPopFront', 'arrayPushBack', 'hasAny', 'arrayReduce', 'length', 'hasAll', 'array', 'countEqual', 'arrayIntersect', 'emptyArrayDateTime', 'arrayJoin', 'emptyArrayFloat64', 'emptyArrayInt32', 'emptyArrayToSingle', 'emptyArrayInt8', 'range', 'arrayPushFront', 'arraySort', 'emptyArrayUInt64', 'arrayEnumerateDense', 'arrayConcat', 'arrayPopBack', 'emptyArrayUInt32', 'arrayDistinct', 'emptyArrayInt16', 'arrayEnumerateUniq', 'emptyArrayUInt8', 'arrayReverseSort', 'arrayReverse' |
round function | 'floor', 'ceil', 'trunc', 'roundAge', 'roundDuration', 'round', 'roundDown' |
mathematical function | 'cbrt', 'erf', 'pow', 'tan', 'atan', 'pi', 'ln', 'power', 'sin', 'asin', 'erfc', 'lgamma', 'tgamma', 'cos', 'sqrt', 'e', 'acos' |
arithmetic function | 'gcd', 'negate', 'plus', 'intDivOrZero', 'intDiv', 'divide', 'lcm', 'modulo', 'minus' |
String Search | 'position','locate','positionUTF8','multiSearchAllPositions','multiSearchFirstPosition','multiSearchFirstIndex','multiSearchAny','match','multiMatchAny','multiMatchAnyIndex','multiFuzzyMatchAny','multiFuzzyMatchAnyIndex','extract','extractAll','like','notLike','ngramDistance','ngramSearch', |
type conversion function | 'toDateTimeOrNull', 'toFloat64OrNull', 'toIntervalDay', 'reinterpretAsFloat32', 'toIntervalMinute', 'toDateTimeOrZero', 'toDecimal32', 'toDecimal64', 'toDateOrNull', 'parseDateTimeBestEffortOrZero', 'reinterpretAsInt32', 'toUInt32OrNull', 'reinterpretAsUInt64', 'reinterpretAsInt64', 'toUInt16OrZero', 'toDate', 'toUInt64', 'toInt32OrNull', 'toIntervalMonth', 'toUInt32OrZero', 'toIntervalHour', 'CAST', 'toInt64OrNull', 'toUInt32', 'toIntervalWeek', 'toDateOrZero', 'reinterpretAsString', 'toUInt16', 'reinterpretAsUInt32', 'reinterpretAsUInt16', 'toUInt64OrNull', 'toInt8', 'reinterpretAsDate', 'reinterpretAsInt8', 'parseDateTimeBestEffortOrNull', 'toIntervalYear', 'toInt16', 'toUInt16OrNull', 'reinterpretAsFloat64', 'toFloat32OrNull', 'toInt32OrZero', 'toUInt8', 'toString', 'reinterpretAsUInt8', 'parseDateTimeBestEffort', 'toFloat64', 'toInt16OrNull', 'toUInt64OrZero', 'toInt8OrZero', 'toInt8OrNull', 'toIntervalQuarter', 'toInt16OrZero', 'toUInt8OrNull', 'toDecimal128', 'toStringCutToZero', 'toUInt8OrZero', 'toInt64OrZero', 'reinterpretAsDateTime', 'reinterpretAsFixedString', 'toFloat64OrZero', 'toInt32', 'toFixedString', 'toFloat32', 'toInt64', 'reinterpretAsInt16', 'toDateTime', 'toIntervalSecond', 'toFloat32OrZero', 'cast','toInt64OrZero' |
Event date function | 'toYear', 'toStartOfInterval', 'toStartOfFifteenMinutes', 'toYYYYMM', 'subtractSeconds', 'addDays', 'addMinutes', 'toStartOfMinute', 'toStartOfFiveMinute', 'toTimeZone', 'subtractQuarters', 'addSeconds', 'addYears', 'toDayOfMonth', 'toDayOfYear', 'toDayOfWeek', 'addWeeks', 'now', 'toStartOfQuarter', 'toStartOfMonth', 'toMinute', 'toRelativeQuarterNum', 'subtractMonths', 'toStartOfTenMinutes', 'subtractHours', 'timeSlot', 'toTime', 'toSecond', 'formatDateTime', 'toStartOfDay', 'today', 'subtractMinutes', 'toRelativeMinuteNum', 'addMonths', 'toMonday', 'toRelativeHourNum', 'toQuarter', 'toStartOfHour', 'toUnixTimestamp', 'toRelativeMonthNum', 'toRelativeSecondNum', 'addQuarters', 'toRelativeDayNum', 'toHour', 'toStartOfISOYear', 'toISOWeek', 'addHours', 'toStartOfYear', 'timeSlots', 'toYYYYMMDD', 'yesterday', 'toMonth', 'subtractWeeks', 'dateDiff', 'subtractYears', 'toRelativeYearNum', 'toISOYear', 'toRelativeWeekNum', 'subtractDays', 'toYYYYMMDDhhmmss''toStartOfWeek','toWeek','toYearWeek', |
Split string function | 'splitByChar', 'splitByString' |
String Replacement Function | 'replaceOne', 'replaceOne','replaceAll', 'replace','replaceRegexpOne'replaceRegexpAll''regexpQuoteMeta' |
string function | 'empty','notEmpty','length','lengthUTF8','char_length','character_length','lower, 'lcase','upper,'ucase','lowerUTF8','upperUTF8','isValidUTF8','toValidUTF8','reverse','reverseUTF8','format','concat','concatAssumeInjective','substring','mid','substr','substringUTF8','appendTrailingCharIfAbsent','convertCharset','base64Encode','base64Decode','tryBase64Decode','endsWith','startsWith','trimLeft','trimRight','trimBoth', |
higher order function | 'arrayCount','arrayEqual','arrayMap','arraySplit','arrayFirst','arrayFirstIndex','arrayMin','arrayMax','arraySum','arrayAvg','arrayExists','arrayFilter', |
JSON function | 'JSONExtractUInt','JSONExtractInt','JSONExtractFloat','JSONExtractBool','JSONExtractString' |
URL function | 'protocol','domain','topLevelDomain','path','pathFull','queryString','extractURLParameters','extractURLParameterNames' |
round function | 'floor','ceil','trunc','round', |
IN operator | 'tuple', 'tupleElement' |
IP function | 'IPv4NumToString','IPv4StringToNum','IPv4NumToStringClassC','IPv6StringToNum','IPv4ToIPv6','cutIPv6','IPv4CIDRToRange,'IPv6CIDRToRange','toIPv4','toIPv6', |
random function | 'rand', 'rand32','rand64','randConstant' |
coding function | 'hex','unhex','UUIDStringToNum','UUIDNumToStrin','bitmaskToList','bitmaskToArray', |
Hash Function | 'halfMD5','MD5','sipHash64','sipHash128','cityHash64','intHash32','intHash64','SHA1','SHA224','SHA256','URLHash','farmHash64','javaHash','hiveHash','metroHash64','jumpConsistentHash','murmurHash2_32','murmurHash2_64','murmurHash3_32','murmurHash3_64,'murmurHash3_128','xxHash32','xxHash64', |
window function | 'row_number' |
For details on how to use the function: https://clickhouse.com/docs/zh/sql-reference/functions/
Error | Severity | Modification proposal | |
|---|---|---|---|
Please add a WHERE clause, otherwise the query may time out. | middle | Add a WHERE clause, otherwise the data from the past 7 days will be queried by default. | |
Lack of event_time or event_date time limit, default query data for the past 7 days. | middle | Add a event_date or event_time condition to the WHERE clause, otherwise the last 7 days are queried by default. | |
Multiple SQL entries were found, but only the first one was executed. | middle | Put the SQL statement that needs to be executed first, or comment out other SQL. (Supports/**/multi-line comments and -- single-line comments.) | |
A character not supported by SQL has been ignored. | middle | Delete unsupported characters in the SQL query. | |
LIMIT clause is missing, up to 1000 items are returned. | middle | Add the LIMIT clause. | |
The maximum number of query results returned is 1000. | middle | The LIMIT clause is limited to 1000. | |
Table name {table_name} is incorrect, please check your SQL. | high | Change the table name to events. | |
Only data from the past 365 days can be queried. Data beyond this range will not be queried. | middle | Limit the query time to nearly 365 days. | |
The data you inquired about is not available in the past 365 days. | high | Limit the query time to nearly 365 days. | |
Up to 20 join clauses are supported, please check your SQL. | high | Reduce the number of JOIN clauses | |
Only SELECT statements are supported, please check your SQL. | high | Only the SELECT statement is retained. | |
No query statement, please check your SQL. | high | ||
SELECT * queries are not supported. Please check your SQL. | high | Query only the columns that need to be queried. | |
Subqueries with more than 10 layers are not supported. Please check your SQL. | high | Reduce the number of subquery layers. | |
The column name {column} for the query does not exist, please check your SQL. | high | Checks whether the column name {column} is in the data table. | |
GROUP BY for up to 30 columns is supported, please check your SQL. | high | Reduce the number of columns after GROUP BY. | |
Table function {table_function} is not supported, please check your SQL. | high | Change the table name to events. | |
There is an unsupported function {function_name}, please check your SQL. | high | Check if the {function_name} is in the list of supported functions. If you need to use this function, please contact customer service. | |
SETTINGS is not supported. Please check your SQL. | middle | Delete the SETTINGS statement, otherwise it is ignored by default. | |
Error in query: {error_message} | high | Modify your SQL statement according to {error_message}. | |
Up to 3 UNION ALL clauses are supported. Please check your SQL. | high | Reduce the number of UNION ALL clauses | |
INTO OUTFILE is not supported, please check your SQL. | high | Delete the INTO OUTFILE clause. | |
FORMAT is not supported, please check your SQL. | high | Delete the FORMAT clause. | |
Unsupported time condition {time_condition}, please check your SQL. | high | event_time time conditions please use integer 10-digit timestamp, event_date time conditions please use "YYYY-MM-dd", e.g. “2020-08-01”。 | |
Query concurrency exceeds the limit. | high | Reduce the concurrency of queries. If you have greater concurrency requirements, please contact customer service. | |
SQL has a syntax error: {syntax_error_msg}. | high | Correct SQL statements based on detailed syntax error information. | |
Use event_time as the event time, not {time_condition}. | high | Use event_time as the event time. | |
Please use {new_column} instead of {old_column}. | middle | high | New column new_column may be provided in place of old_column due to technical upgrades or other reasons. |
Invalid time condition (details: {cause}). | high | Unwritten or problematic time conditions, such as event_date > = '2020-08-05' and event_date = '2020-08-01' | |
Example: The time condition is invalid (details: the time limit is derived as empty). | |||
Could not derive {target_condition}, please add {target_condition} constraint. | high |
| |
Example: Unable to derive event_date, please add event_date constraints. |
| ||
Please give {column} an alias, otherwise the query may report an error. | middle | For user_profiles.xxx, event_param.xxx .yyy, item_profiles .xxxx.yyy columns, it is recommended to alias, otherwise there may be an error. | |
Error code | Error message | Common Error Causes | |||||
|---|---|---|---|---|---|---|---|
215 | xxxxxx is not under aggregate function and not in GROUP BY | SQL query columns are not in GROUP BY, for example: | |||||
select event, user_profiles.user_id from events group by event; | |||||||
Modify it to: | |||||||
select event, user_profiles.user_id from events group by event, user_profiles.user_id; | |||||||
Or: | |||||||
select event, any(user_profiles.user_id) from events group by event; | |||||||
43 | Illegal types of arguments (xxx, yyy)of function [equals | greater | greaterOrEquals | less | lessOrEquals | notEquals ] | The two sides of the comparison character are not of the same type, for example: |
The price attribute of the event buy is of type int, which should be | |||||||
select event from events where event_param.buy.price != '1'; | |||||||
Modify it to: | |||||||
select event from events where event_param.buy.price != 1; | |||||||
53 | ARRAY JOIN requires array argument | Type mismatch, for example: | |||||
select arrayJoin(event_params.force.$target_uuid_list) | |||||||
62 | Syntax error: failed at position xxxx | Check for detailed errors, such as: | |||||
select event from events where event as e = 'app_launch' limit 20; | |||||||
The error message is: | |||||||
Query error: code: 62, detail_message: DB:: Exception DB :: Exception: Syntax error: failed at position 239: = 'app_launch') and (tea_app_id = 41514 and event_date > = '2021-03-09' and event_date < = '2021-03-15') limit 20;. Expected one of: token, Comma. | |||||||
After observation, it was found that the error occurred around **= 'app_launch' **. After investigation, it was found that the event as e syntax was wrong and should be changed to: | |||||||
select event from events where event = 'app_launch' limit 20; | |||||||
202 | Too many simultaneous queries. | The current database query is busy. Please try again later. | |||||
42 | Number of arguments for function xxxx doesn't match | The number of parameters does not match, for example: | |||||
select least(user_profiles.user_id) from events limit 20; | |||||||
The error message is: | |||||||
Query error: code: 42, detail_message: DB:: Exc ep t ion DB :: Exc ep t ion: Number of arguments for function least doesn't match: passed 1, should be 2. | |||||||
After querying the manual, it was found that the least function requires 2 parameters and returns the smaller of the two parameters. | |||||||
|
Query the country ID of active users after August 1, 2020:
select user_profiles.loc_country_id from users where last_active_date > '2020-08-01' limit 200;
The format of the user property column names is user_profiles. {user_profile_name}.
The format of the event property column names is event_params. {event_name}. {event_param_name}. An example is as follows:
select user_profiles.os_name, event_params.app_launch.session_duration, network_type, device_brand, event_time from events and event_date >= '20200812' and event_date <= '20200819' limit 20;
Note: Although the WHERE condition in the sample SQL does not contain event = 'app_launch', according to
event_params app_launch session_duration field semantics will still only query session_duration attribute values under app_launch events.
If you need to query the attribute value of the same attribute name under different events, please contact customer service.
It can be viewed in DataRangers' "Data Management" feature.
Search for "event_params" in the data table to see how all events correspond to event properties.
The business object property column name format is item_profiles. {item_name}. {item_param_name}. An example is as follows:
select item_profiles.book.name, item_profiles.book.authors, item_profiles.phone.price from items limit 30;
The query business object is the name and author of the book, and the query business object is the price of the phone. Similar to the query event properties, the sample SQL does not specify item_name in ('book', 'phone'), but the custom query function automatically derives item_name based on the semantics of fields such as item_profiles.book. Authors, so the sample SQL is equivalent to the following SQL:
select item_profiles.book.name, item_profiles.book.authors, item_profiles.phone.price from items where item_name in ('book', 'phone') limit 30;
JOINs of transaction table and user table can be done through hash_uid. An example is as follows:
select gender, hash_uid, user_id from events as table_a left join ( select hash_uid, user_profiles.gender as gender from users where user_profiles.gender is not null ) as table_b on table_a.hash_uid == table_b.hash_uid where event_date <= '2020-08-10' and event = 'A' limit 500;
Note: It is recommended to use hash_uid for JOIN, JOIN through other fields may cause the query to time out.
You can do a JOIN query by event_params the xxx_hash_item_id of the corresponding event and the hash_item_id of the corresponding business object in the items table. An example is as follows:
select event_params.buy.book_hash_item_id as book_item_id, event_params.buy.browser as buy_browser, item_table.book_name, from events event_table any inner join (select hash_item_id, item_profiles.book.name as book_name, from items where item_name = 'book') item_table on arrayJoin(if(isNotNull(event_params.buy.book_hash_item_id), assumeNotNull(event_params.buy.book_hash_item_id), [NULL])) = item_table.hash_item_id where event_date > '2020-12-10' limit 20;
The role of the above example is to query the value of the browser and the name of the book when the business object attribute associated with the buy event is book.
Note:
arrayJoin(if(isNotNull(event_params.buy.book_hash_item_id), assumeNotNull(event_params.buy.book_hash_item_id), [NULL]))
Converts book_hash_item_id of Array type to scalar for JOIN convenience.
The $is_first_day attribute is a virtual event attribute, and the Finder query side compares the $is_first_day attribute value according to the user event occurrence time and the user's first time occurrence time. If you need to query, you can refer to the following SQL:
select (toStartOfDay(toDateTime(event_time, 'Asia/Shanghai')) == toStartOfDay(toDateTime(ut.first_event_time, 'Asia/Shanghai'))) as `$is_first_day` from events et global any inner join ( select hash_uid, user_profiles.first_event_time as first_event_time from users ) ut on et.hash_uid == ut.hash_uid where event = 'browse' and event_date >= '2020-12-22' and event_date <= '2020-12-28';
select toUInt32((event_time - toUnixTimestamp('2020-12-22', 'Asia/Shanghai')) / 86400) as t, count(1) as cnt from events et global any inner join ( select hash_uid, user_profiles.first_event_time as first_event_time from users ) ut on et.hash_uid == ut.hash_uid where event = 'browse' and event_date >= '2020-12-22' and event_date <= '2020-12-28' and (toStartOfDay(toDateTime(event_time, 'Asia/Shanghai')) == toStartOfDay(toDateTime(ut.first_event_time, 'Asia/Shanghai'))) group by t order by t ;
Because during the behavioral scrutiny, the uuid will be converted into an ssid query, so both real-name and anonymous behaviors can be found. However, in a custom query, if user_id = xxx is given in SQL, only real-name behavior will be queried, not anonymous behavior.
Custom queries currently do not support "old and new users", virtual properties, virtual events, and circled events.
Alternatives are:
Event public properties usually appear as follows:
event_params.any_event.公共属性名 event_params.any_active_event.公共属性名 event_params.事件名.公共属性名 event_params.公共属性名
When querying the following SQL, the scope of the query is all events.
select event_params.any_event.common_param_a from events; 或者 select event_params.common_param_a from events;
When querying the following SQL, the scope of the query is all active events.
select event_params.any_active_event.common_param_a from events;
When querying the following SQL, the scope of the query is event_1 events.
select event_params.event_1.common_param_a from events;
The above SQL is equivalent to -
select event_params.any_event.common_param_a from events where event = 'event_1';
If a SQL contains event_params any_event.xxx, event_params any_active_event.xxx, event_params. Specific event name.xxx, then the event restriction rules for the query are as follows:
Condition | Rule |
|---|---|
SQL contains event_params. Event name. Public property name | Automatically derive event names as a limitation, the relationship between multiple specific event names is or |
SQL contains event_params any_active_event... public attribute name | Limit active events. |
SQL contains event_params any_event... public attribute name | No restrictions on events. |
The relationship between rules is or, for example:
Query the event public property fields contained in SQL | Derived event query limits |
|---|---|
| Unlimited |
| event_1 or event_2 or active events |
| event_1 or event_2 |
| Unlimited |
| Unlimited |
Use the event_param event property name so that custom queries do not automatically assemble event limits, requiring you to specify the event in the WHERE condition, such as:
select event_params.url as url from events where event in ('event_1', 'event_2') and event_date = today();
Note: If there are many events containing this property, it may result in an increase in SQL parsing time.
Current custom SQL queries do not support SQL queries using dynamic parameters, such as:
select event, event_time from events where event = ‘app_launch’ and event_date = ${event_date} limit 20; --Where event = ${event_name} This dynamic parameter is passed in by subsequent dynamic, SQL queries in the form of such dynamic parameters are currently not supported