如何从我在数据集内创建的特定 table 的搜索中收到的答案中删除其他不需要的名称?

How can I remove an additional unwanted name from the answers i have received within a search in a specific table created within a dataset?

我试图从我根据某些数据创建的 table 中删除两个不需要的答案。但是,一旦我添加要删除的其他名称,两个名称都不会被删除。是否有一个选项可以从 table?

中删除多个答案(在我的例子中是名字)

请看代码:

SELECT
  person,
  COUNT(1) AS count_mentions,
  COUNT(DISTINCT url) AS count_distinct_urls
FROM
  `robust-cycle-309917.56146_2021_big_data.israel_media_person`
WHERE lower(person) not like '%gaza%' OR lower(person) not like '%Maccabi Haifa%'
GROUP BY
  person
ORDER BY
  count_mentions DESC
LIMIT
  10;
 

你的 where 子句应该使用 AND 而不是 OR

所以

WHERE lower(person) not like '%gaza%' OR lower(person) not like '%Maccabi Haifa%'

应该是

WHERE lower(person) not like '%gaza%' AND lower(person) not like '%Maccabi Haifa%'

We must also remove the extra space on the right to match. Try this:

SELECT
  person,
  COUNT(1) AS count_mentions,
  COUNT(DISTINCT url) AS count_distinct_urls
FROM
  `robust-cycle-309917.56146_2021_big_data.israel_media_person`
WHERE
  LOWER(RTRIM(person)) NOT LIKE 'gaza gaza'
  AND LOWER(RTRIM(person)) NOT LIKE 'maccabi haifa'
GROUP BY
  person
ORDER BY
  count_mentions DESC
LIMIT
  10;

-- Result
--  person  count_mentions  count_distinct_urls
--  Benjamin Netanyahu  32,455  20,302
--  Reuben Castro   21,093  3,366
--  Donald Trump    13,643  7,728
--  Medinat Yisrael     12,372  8,894
--  Benny Gantz     10,551  5,542
--  Oz Muallem  10,514  3,860
--  Reuben Schwartz     9,232   3,631
--  Yedioth Ahronoth    8,587   4,401
--  Moshe Kahlon    8,480   6,521
--  Miri Regev  7,853   4,907 

两分

  • 如果您需要删除两个名称,那么您应该使用“and”而不是“or”

  • 如果你使用函数 lower() 那么它应该是

    较低(人)不喜欢“%maccabi haifa%”

而不是

lower(person) not like '%Maccabi Haifa%'