get average of number of likes in mysql from two tables
You can use the COALESCE function to return zero if it has no results like so:

SELECT posts.post_id, posts.text , COALESCE(AVG(ranks.score),0) as `ranking` 
  FROM posts 
  JOIN ranks 
    ON ranks.post_id = posts.post_id 
 GROUP BY posts.post_id;