繁体   English   中英

列值出现超过 X 次

[英]Column value occurs more than X times

我正在尝试仅 select 行,其中trends.insights_taxonomy列值出现超过 X 次。 我一直在避免使用 COUNT(),因为我不做任何分组,我希望所有相关的行保持唯一。

我试图剔除异常值,例如,如果我有一个包含 10 万人最喜欢的 colors 的数据库,我想忽略出现次数少于 50 次的 colors。

这是子查询的用武之地吗?

SELECT insights.industry,insights.city,insights.country,metrics.engagements,metrics.number_of_people_at_company, trends.insights_taxonomy,
FROM production.scores.api_company,
UNNEST(insights) AS insights,
UNNEST(metrics) AS metrics,
UNNEST(trends) AS trends
WHERE insights.industry <> ""
AND insights.city <> ""
AND insights.country <> ""
AND metrics.number_of_people_at_company > 0
AND metrics.engagements > 10

不确定格式化它的最佳方式,但第一行是列标签,第二行是值。 在这种情况下,我只想要 Cisco Systems 出现次数超过 X 次的行。

industry | city | country | engagements | people_at_company | taxonomy
Legal Counsel and Prosecution | Madison | United States | 11 | 5 | Cisco Systems

如果您不想对结果数据进行分组,则需要在获取结果数据之前确定符合条件的行。 编写分组查询以确定符合条件的行,然后您可以根据上面的查询加入数据集以收集所有内容而不进行分组,或者执行 WHERE x IN(您的分组子查询返回您想要查看完整数据的有效内容).

我想通了使用子查询,希望这对其他人有帮助。

SELECT insights.industry,insights.city,insights.country,metrics.engagements,metrics.number_of_people_at_company, trends.insights_taxonomy, trends.total_interactions
FROM production.scores.api_company,
UNNEST(insights) AS insights,
UNNEST(metrics) AS metrics,
UNNEST(trends) AS trends
WHERE trends.insights_taxonomy IN 
  (SELECT trends.insights_taxonomy
  FROM production.scores.api_company,
  UNNEST(trends) AS trends
  GROUP BY insights_taxonomy
  HAVING count(*) > 100)
AND insights.city <> ""
AND insights.country <> ""
AND metrics.number_of_people_at_company > 0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM