I need to calculate the average from a mysql table. So I am taking the sum of a col and dividing it by the number of rows. But the values are not being assigned properly :-
$total_sum_query = $db->query("SELECT SUM(marks) FROM markstable WHERE sid = '$sid'");
$num_rows_query = $db->query("SELECT * FROM markstable WHERE sid = '$sid'");
$avg_marks = $total_sum_query/$num_rows_query;
I know i am doing something wrong but can not figure it out. Is there a way to derive the average in mysql?