How can I count the number of times each employee ID appears in a dataset?
💡 Model Answer
In SQL you can use a GROUP BY clause to aggregate the rows by employee_id and then count the occurrences. For example:
SELECT employee_id, COUNT(*) AS duplicate_count
FROM employees
GROUP BY employee_id
HAVING COUNT(*) > 1;
This query returns only those employee IDs that appear more than once, along with the number of times they appear. In Python with pandas you can achieve the same with:
duplicate_counts = df['employee_id'].value_counts()
print(duplicate_counts[duplicate_counts > 1])
Both approaches give you a quick view of which employee IDs are duplicated and how many times.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500