sql 马来西亚物业展
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 马来西亚物业展相关的知识,希望对你有一定的参考价值。
CREATE TEMPORARY FUNCTION
last_n(x STRING,
n FLOAT64,
delimiter STRING)
RETURNS STRING
LANGUAGE js AS """
if (x == null ) {return null} else if (x.split(delimiter).slice(-n,-1) == "") {return x.split(delimiter).pop()} else {return [x.split(delimiter).slice(-n,-1), x.split(delimiter).pop()]};
""";
SELECT
hits_pagepath,
last_n(hits_pagepath,1, '-') as listing_id,
vlisting_id,
hits_pagepath_level1,
city
FROM
`propertyguru-datalake-v0.ods.my_seeker_events_denormed`
WHERE
_PARTITIONTIME >= "2018-11-19 00:00:00"
AND _PARTITIONTIME < "2018-11-22 00:00:00"
AND city = 'Singapore'
LIMIT
1000
SELECT
id,
region_code
FROM
`propertyguru-datalake-v0.propertydb_staging.my_v_listing`
LIMIT
1000
MY01 - JH <---
MY02 - KD
MY03 - KT
MY04 - ML <---
MY05 - NS
MY06 - PH
MY07 - PG <---
MY08 - PR
MY09 - PS
MY10 - SL
MY11 - TR
MY12 - SB
MY13 - SW
MY14 - KL <---
CREATE TEMPORARY FUNCTION
last_n(x STRING,
n FLOAT64,
delimiter STRING)
RETURNS STRING
LANGUAGE js AS """
if (x == null ) {return null} else if (x.split(delimiter).slice(-n,-1) == "") {return x.split(delimiter).pop()} else {return [x.split(delimiter).slice(-n,-1), x.split(delimiter).pop()]};
""";
WITH
seeker_tb AS (
SELECT
last_n(hits_pagepath,1, '-') as listing_id,
city
FROM
`propertyguru-datalake-v0.ods.my_seeker_events_denormed`
WHERE
_PARTITIONTIME >= "2018-11-20 00:00:00"
AND _PARTITIONTIME < "2018-11-21 00:00:00"
AND city = 'Singapore'
group by 1,2
),
listing_tb AS (
SELECT
CAST(id as STRING) as id,
region_code
FROM
`propertyguru-datalake-v0.propertydb_staging.my_v_listing`
-- group by 1,2
)
SELECT
id,
region_code
FROM listing_tb
INNER JOIN seeker_tb
ON seeker_tb.listing_id = listing_tb.id
LIMIT 1000
-- CREATE TEMPORARY FUNCTION
-- last_n(x STRING,
-- n FLOAT64,
-- delimiter STRING)
-- RETURNS STRING
-- LANGUAGE js AS """
-- if (x == null ) {return null} else if (x.split(delimiter).slice(-n,-1) == "") {return x.split(delimiter).pop()} else {return [x.split(delimiter).slice(-n,-1), x.split(delimiter).pop()]};
-- """;
SELECT
hits_pagepath,
SPLIT(hits_pagepath, '-')[SAFE_OFFSET(ARRAY_LENGTH(SPLIT(hits_pagepath, '-')) - 1)] as listing_id,
-- last_n(hits_pagepath,1, '-') as listing_id,
vlisting_id,
hits_pagepath_level1,
city,
status_code
FROM
`propertyguru-datalake-v0.ods.my_seeker_events_denormed`
WHERE
_PARTITIONTIME >= "2018-11-19 00:00:00"
AND _PARTITIONTIME < "2018-11-22 00:00:00"
AND city = 'Singapore'
以上是关于sql 马来西亚物业展的主要内容,如果未能解决你的问题,请参考以下文章