Explained | Group By With Having | SQL and Pandas
My SQL\nYou can add conditions to group by clause by using having clause.\nAdd actor_id, director_id to group by because they are being selected for showing. An
# My SQL\nYou can add conditions to `group by` clause by using `having` clause.\nAdd `actor_id, director_id` to group by because they are being selected for showing. Anything that\'s not inside an aggregate function (`count()`, `avg()`, `max()`, etc.) and needs to be shown as output must be written inside `GROUP BY` clause.\n\n``` SQL []\n# Write your MySQL query statement below\nSELECT actor_id, director_id\nFROM ActorDirector\nGROUP BY actor_id, director_id\nHAVING count(timestamp)>=3\n```\n\n# Pandas\n\nIf you understand the SQL clearly, you will be able to come up with the following solution.\n\n``` python3 []\nimport pandas as pd\n\ndef actors_and_directors(ad: pd.DataFrame) -> pd.DataFrame:\n  df = ad.groupby([\'actor_id\', \'director_id\']).count().reset_index()\n  return df[df[\'timestamp\']>=3][[\'actor_id\', \'director_id\']]\n```
['MySQL', 'Pandas']