Last active
November 5, 2015 07:53
-
-
Save itochu0523/007241bd4df289b34e4f to your computer and use it in GitHub Desktop.
##トレジャーデータのJSSDKで収集したログでユーザーセグメントを作成する方法 ref: http://qiita.com/itochu0523/items/4113e35c587ab40c384f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Presto | |
| SELECT | |
| a.td_client_id as td_client_id | |
| ,a.td_os as td_os | |
| ,'Weekly_Over5_Accesses' as segment_name | |
| FROM | |
| ( | |
| SELECT | |
| td_client_id | |
| ,td_os | |
| ,count(1) as cnt | |
| FROM | |
| access | |
| WHERE | |
| TD_TIME_RANGE(time,'2015-05-24 00:00:00','2015-05-31 00:00:00','JST') | |
| GROUP BY td_client_id,td_os | |
| HAVING count(1) >= 5 | |
| ) as a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Presto | |
| SELECT | |
| a.hour as hour | |
| ,a.td_client_id as td_client_id | |
| ,a.td_os as td_os | |
| ,'Hour_Over5_Access' as segment_name | |
| FROM | |
| ( | |
| SELECT | |
| td_time_format(time,'HH') as hour | |
| ,td_client_id | |
| ,td_os | |
| ,count(1) as cnt | |
| FROM | |
| access | |
| WHERE | |
| TD_TIME_RANGE(time,'2015-04-01 00:00:00','2015-06-01 00:00:00','JST') | |
| GROUP BY | |
| td_time_format(time,'HH') | |
| ,td_client_id | |
| ,td_os | |
| HAVING count(1) >= 5 | |
| ) as a | |
| WHERE | |
| a.hour BETWEEN '20' AND '23' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Hive | |
| SELECT | |
| a.weekday as weekday | |
| ,a.td_client_id as td_client_id | |
| ,a.td_os as td_os | |
| ,'Weekday_Over5_Access' as segment_name | |
| FROM | |
| ( | |
| SELECT | |
| weekofyear(td_time_format(time,'yyyy-MM-dd')) as weekday | |
| ,td_client_id | |
| ,td_os | |
| ,count(1) as cnt | |
| FROM | |
| access | |
| WHERE | |
| TD_TIME_RANGE(time,'2015-04-01 00:00:00','2015-06-01 00:00:00','JST') | |
| GROUP BY | |
| weekofyear(td_time_format(time,'yyyy-MM-dd')) | |
| ,td_client_id,td_os | |
| HAVING count(1) >= 5 | |
| ) as a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| td_client_id, | |
| td_os, | |
| COUNT(1) AS cnt | |
| FROM | |
| access | |
| WHERE | |
| TD_TIME_RANGE(time,'2015-04-01 00:00:00','2015-06-01 00:00:00','JST') | |
| AND td_path = '/201506FreeUserSeminar_marketo-summit-2015-thankyou.html' | |
| GROUP BY | |
| td_client_id, | |
| td_os | |
| ORDER BY | |
| cnt DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WHERE td_os in ('iOS','Android') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| td_os in ('iOS') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| td_os like '%Windows%' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| td_ip | |
| ,count(distinct(td_client_id)) as cnt | |
| FROM | |
| access | |
| WHERE | |
| TD_TIME_RANGE(time,'2015-04-01 00:00:00','2015-06-01 00:00:00','JST') | |
| GROUP BY | |
| td_ip | |
| HAVING | |
| count(distinct(td_client_id)) > 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment