sql AIME软和硬悬浮图像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql AIME软和硬悬浮图像相关的知识,希望对你有一定的参考价值。
WITH
listing_table AS (
SELECT
id,
agent_id
FROM
`propertyguru-datalake-v0.propertydb_staging.sg_v_listing_active`
WHERE status_code = 'ACT'
GROUP BY 1,2),
active_listing AS (
SELECT
agent_id,
owner_id AS listing_id,
media.id AS image_id,
media.status_code AS image_status
FROM
`propertyguru-datalake-v0.propertydb_staging.sg_media` media
INNER JOIN listing_table lt
ON lt.id = media.owner_id
WHERE status_code IN ('ACT','SUSP')
),
image_table AS (
SELECT
media_id as image_id,
status AS moderator_status,
media_url,
updated_at
FROM
`propertyguru-datalake-v0.propertydb_staging.sg_media_moderator_status`
),
image_table_complete AS (
SELECT
agent_id,
listing_id,
al.image_id,
image_status,
moderator_status,
media_url,
updated_at
FROM active_listing al
LEFT JOIN image_table it
ON al.image_id = it.image_id
ORDER BY 1,2 ),
agent_table AS (
SELECT
agent_id,
mobile,
email,
firstname,
lastname,
agency_name,
status_code,
account_rule_code
FROM
`propertyguru-datalake-v0.propertydb_staging.sg_v_agent_search`
WHERE status_code = 'ACT'
),
final_table AS (
SELECT
listing_id,
image_id,
image_status,
moderator_status,
media_url,
img.agent_id,
mobile,
email,
firstname,
lastname,
agency_name,
status_code,
account_rule_code,
updated_at
FROM image_table_complete img
LEFT JOIN agent_table agt
ON img.agent_id = agt.agent_id
),
agg_image_table AS (
SELECT
agent_id,
listing_id,
COUNT(IF(moderator_status = 'PASSED', 1, NULL)) AS passed_count,
COUNT(IF(image_status = 'ACT' AND moderator_status = 'SUSPENDED', 1, NULL)) AS soft_suspended_count,
COUNT(IF(image_status = 'SUSP' AND moderator_status = 'SUSPENDED', 1, NULL)) AS hard_suspended_count,
COUNT(IF(moderator_status = 'FLAGGED', 1, NULL)) AS flagged_count
FROM image_table_complete
GROUP BY 1,2
ORDER BY 1,2,3),
final_agg_table AS (
SELECT
listing_id,
img.agent_id,
passed_count,
soft_suspended_count,
hard_suspended_count,
flagged_count,
mobile,
email,
firstname,
lastname,
agency_name,
status_code,
account_rule_code
FROM agg_image_table img
LEFT JOIN agent_table agt
ON img.agent_id = agt.agent_id
)
SELECT
agent_id,
mobile,
email,
firstname,
lastname,
agency_name,
status_code,
account_rule_code,
COUNT(listing_id) AS total_active_listing,
COUNT(CASE WHEN (soft_suspended_count + hard_suspended_count) > 0 THEN 1
WHEN flagged_count > 0 THEN 1
ELSE NULL END) AS total_listing_with_faulty_img,
COUNT(CASE WHEN passed_count < 3 THEN 1
ELSE NULL END) AS total_listing_less_than_3_good_img,
SUM(passed_count) AS total_passed_img,
SUM(soft_suspended_count) AS total_soft_suspended_img,
SUM(hard_suspended_count) AS total_hard_suspended_img,
SUM(flagged_count) AS total_flagged_img
FROM final_agg_table
GROUP BY 1,2,3,4,5,6,7,8
ORDER BY 13 DESC,14 DESC
以上是关于sql AIME软和硬悬浮图像的主要内容,如果未能解决你的问题,请参考以下文章