We help IT Professionals succeed at work.

MySQL Count Query

dbasaurus
dbasaurus asked
on
I have a MySQL table that contains an employee number, and a column called action. For example:

employee_id   action
1                     change address
1                     change address
1                     change address
1                     change address
1                     transfer
1                     vacation
1                     change address
1                     change address
2                     change address
2                     change address
2                     transfer
2                    vacation
4                     change address
4                     change address
4                     change address
3                     change address
1                     transfer
1                     vacation

What I want to do is create a result set that has how many employee_ids have changed there address more than once.
Comment
Watch Question

SELECT employee_id,
COUNT(action) AS itemsCount
FROM your_employee_action_table
WHERE action = 'change address'
GROUP BY employee_id
HAVING itemsCount > 1

Explore More ContentExplore courses, solutions, and other research materials related to this topic.