MySQLしかろくに使ってこなかった人間が知って便利だった Presto & Treasure Data 小ネタ ref: http://qiita.com/inuscript/items/061a6ab5fd6564e8686c
SELECT
CASE ua
WHEN 'IE' THEN family || '_'|| version
WHEN 'Chrome' THEN family
WHEN 'Firefox' THEN family
WHEN 'Safari' THEN family
WHEN 'Opera' THEN family
ELSE 'Other'
END
SELECT coalesce(a, b)
-- IEだけversion付けたいみたいなとき
SELECT
if(family='IE', family || version, family)
SELECT a || '_' || b
FROM *
WITH config AS (
SELECT
TD_TIME_ADD(TD_SCHEDULED_TIME(),'-10d', 'JST') AS start_time,
TD_TIME_ADD(TD_SCHEDULED_TIME(),'-1d', 'JST') AS end_time
)
SELECT *
FROM access, config
WHERE TD_TIME_RANGE(time, config.start_time, config.end_time, 'JST')
WITH
config AS (
SELECT 2 AS val_a
),
tbl AS (
SELECT
val_a,
some_value * val_a -- some_value * 2
FROM some_table, config
)
SELECT * FROM tbl
WITH a AS (
SELECT * FROM some_table
),
b AS (
SELECT * FROM a
),
c AS (
SELECT * FROM a
)
SELECT * FROM c, b
WITH a AS (
SELECT * FROM some_table
),
b AS (
SELECT * FROM a
),
c AS (
SELECT * FROM b
)
SELECT * FROM c
SELECT TD_SESSIONIZE(time, 3600, ip_address) as session_id
FROM ...
ORDER BY ip_address, time -- ソートする
SELECT
*
TD_PARSE_AGENT(user_agent)['ua_family'] AS family,
TD_PARSE_AGENT(user_agent)['ua_major'] AS version
FROM
access
WHERE TD_PARSE_AGENT(user_agent) IN ['pc', 'smartphone']
WITH a AS (
SELECT
TD_PARSE_AGENT(user_agent)['ua_family'] AS family,
TD_PARSE_AGENT(user_agent)['ua_major'] AS version
FROM
access
),
b AS (
SELECT
if(family = 'IE', family || version, family) AS browser
FROM b
),
SELECT
TD_PARSE_AGENT(user_agent)['os_family']
TD_PARSE_AGENT(user_agent)['os_major']
TD_PARSE_AGENT(user_agent)['os_minor']
TD_PARSE_AGENT(user_agent)['ua_family']
TD_PARSE_AGENT(user_agent)['ua_major']
TD_PARSE_AGENT(user_agent)['ua_minor']
TD_PARSE_AGENT(user_agent)['device']
FROM access
SELECT
:
WHERE
-- 1日間のデータなら -1d。一ヶ月なら-30dとか。
TD_TIME_RANGE(time,
TD_TIME_ADD(TD_SCHEDULED_TIME(), '-1d', 'JST'),
null
'JST'
)
SELECT
some_name,
map_keys(
histogram(some_type)
)
FROM foo
GROUP BY some_name
SELECT *
FROM access TABLESAMPLE BERNOULLI(1)
EXPLAIN (FORMAT GRAPHVIZ)
SELECT * FROM ...
SELECT * FROM (
SELECT * FROM (
SELECT * AS day
:
)
)
SELECT *
FROM access
WHERE
url_extract_host(referer) = "google.com"
-- 正規表現でやるとこんな感じ
-- regexp_like(referer, '.*google.com/.*')