I've been searching and I know there are similar questions, but none of them seems to answer this particular question.
I am trying to get a count of the total number of days an employee has worked on a given schedule. To do this, I am counting the total number of rows the employee appears on the "schedules" table. Only we run into a problem if the employee is scheduled twice on the same day.
To solve this, I want to count total number of rows and sort by DATE in a DATETIME field.
Current query:
$days = mysql_query("SELECT emp_id FROM schedules
WHERE sch_id = '$sch_id'
AND emp_id = '$emp_data[emp_id]'");
$tot_days = mysql_num_rows($days);
I would like to change it to:
$days = mysql_query("SELECT emp_id FROM schedules
WHERE sch_id = '$sch_id'
AND emp_id = '$emp_data[emp_id]'
GROUP BY start_date");
// "start_date" is a datetime field. Need to sort by date only YYYY-MM-DD
$tot_days = mysql_num_rows($days);
Any thoughts?
ORDER BY start_dateto the end of the 2nd one.