Hi,
can anyone explain me what’s the right way to use the group by clause ?
for instance
SELECT A.domain_id, U.birthday AS field, DATE( access_start_datetime ) AS DATE, COUNT( A.id ) AS value
FROM stats_access A
JOIN users U ON U.id = A.fb_id
GROUP BY DATE( A.access_start_datetime ) , U.birthday, A.domain_id
with this query I get the number of the users group by access_start_datetime,birthday and domain_id
Is it right ?
It works fine but I’d a doubt.
All in all I’d like to know what’s the
rules to apply group by
from http://www.tizag.com/mysqlTutorial/mysqlgroupby.php
Some technical rules of GROUP BY:
The column that you GROUP BY must also be in your SELECT statement.
Remember to group by the column you want information about and not the one you are applying the aggregate function on. In our above example we wanted information on the type column and the aggregate function was applied to the price column.
Is it enough ?