Skip to content
Advertisement

How to count mention in one day [closed]

I am try to understant how to make a table that tells me in which specific day were written the most mentions about the persons in my table.

SELECT
 person,
  COUNT(1) AS count_mentions,
  COUNT(DISTINCT current_date) AS mention_per_date,
FROM
  `aesthetic-honor-311413.big_data_alon_peled_2021.israel_media_person`
  GROUP BY
  person
ORDER BY
  current_date asc
LIMIT
  10;

EXPECTED RESULT:

person  mention_per_date
Tomer          24
Shalev         18
Yosef          15
Eran           15
Gal            11
(Fictive names and numbers)

Advertisement

Answer

I am try to understant how to make a table that tells me in which specific day were written the most mentions about the persons in my table.

For this question, I would expect a query like this:

SELECT person, date, COUNT(*)
FROM `aesthetic-honor-311413.big_data_alon_peled_2021.israel_media_person`
GROUP BY person, date
QUALIFY ROW_NUMBER() OVER (PARTITION BY person ORDER BY COUNT(*) DESC) = 1;

This returns the date that most frequently occurs for each person. You don’t mention the name of the date column, so this just uses date.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement