sql MySQLしかろくに使ってこなかった人间が知って便利だったPresto&Treasure Data小ネタ参考:http://qiita.com/inuscript/items/061a

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MySQLしかろくに使ってこなかった人间が知って便利だったPresto&Treasure Data小ネタ参考:http://qiita.com/inuscript/items/061a相关的知识,希望对你有一定的参考价值。

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/.*')

以上是关于sql MySQLしかろくに使ってこなかった人间が知って便利だったPresto&Treasure Data小ネタ参考:http://qiita.com/inuscript/items/061a的主要内容,如果未能解决你的问题,请参考以下文章

桜川未央 - 隠した涙

php 的foreachで记事を取得している时に,记事がなかった场合の处理も制御する

php 的foreachで记事を取得している时に,记事がなかった场合の处理も制御する

笑い話

15もしそうなら?たとえそうでも

php 【WordPress的】复数のタクソノミを条件に使った复合検索をする