1. Inner Joints 表示链接两个表格共有部分。(Inner Joints)
当两个表格的列名相同时,为避免歧义,需指定从哪个表格进行引用的说明。
%%sql SELECT d.dog_guid AS DogID, d.user_guid AS UserID, AVG(r.rating) AS AvgRating, COUNT(r.rating) AS NumRatings, d.breed, d.breed_group, d.breed_type FROM dogs d, reviews r WHERE d.dog_guid=r.dog_guid AND d.user_guid=r.user_guid GROUP BY UserID, DogID, d.breed, d.breed_group, d.breed_type HAVING NumRatings >= 10 ORDER BY AvgRating DESC LIMIT 200;
2.从多个表进行结合。
SELECT c.user_guid AS UserID, u.state, u.zip, d.dog_guid AS DogID, d.breed, d.breed_type, d.breed_group FROM dogs d, complete_tests c, users u WHERE d.dog_guid=c.dog_guid AND c.user_guid=u.user_guid AND c.test_name="Yawn Warm-up";