SELECT user.name, DATE( office.created_at ) AS Date, office.id FROM office, user WHERE user.group_id =1 AND created_by = user.id
Now the query displays the following
USER | Date | ID ---------+--------------+-------- юзер1 24.12.2012 1 юзер1 24.12.2012 2 юзер1 25.12.2012 3 юзер2 25.12.2012 4 юзер3 24.12.2012 5
How to change the query so that the dates do not repeat and instead of the ID field there is not a value, but their number?
USER | Date | Count --------+---------------+-------- юзер1 24.12.2012 2 юзер1 25.12.2012 1 юзер2 25.12.2012 1 юзер3 24.12.2012 1
Answer:
SELECT COUNT( * ) AS Cnt, user.name, DATE( office.created_at ) AS Date FROM office, user WHERE user.group_id =1 AND created_by = user.id GROUP BY user.name, DATE( office.created_at ) ORDER BY user.name, DATE( office.created_at )