tommyda Posted January 22, 2009 Share Posted January 22, 2009 ERROR:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND avg(quality_rating) AS quality_rating AND avg(delivery_time) AS delivery_tim' at line 1 I am trying to find the average of 3 columns then find the average of the averages. That sounds confusing but I dont know how to word it so heres an code, its pretty self explanitory what I am trying to do. $ratingq = mysql_query("SELECT avg(price_rating) AS price_rating AND avg(quality_rating) AS quality_rating AND avg(delivery_time) AS delivery_time FROM ratings WHERE s_id = '$s_id' ") or die(mysql_error()); $rarow = mysql_fetch_array( $ratingq ); $total = $rarow['price_rating'] + $rarow['quality_rating'] + $rarow['delivery_time']; $num = "3"; $avg = $total / $num; $rounded = round($avg); echo'</a> </br>Overall Rating: '.$rounded.'/5'; Can anyone tell me what I am doint wrong please? Link to comment https://forums.phpfreaks.com/topic/141899-solved-problems-with-averages-avg/ Share on other sites More sharing options...
zenag Posted January 22, 2009 Share Posted January 22, 2009 use comma instead of AND "SELECT avg(price_rating) AS price_rating, avg(quality_rating) AS quality_rating , avg(delivery_time) AS delivery_time FROM ratings Link to comment https://forums.phpfreaks.com/topic/141899-solved-problems-with-averages-avg/#findComment-742995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.